Facebook4j - "null information" from FriendList - java

I've been trying to get some informations from my Friends throught facebook4j. But every time I try to do it I receive only null pointers (except on id/name).
Here's the code:
`
Stalker(String victimUsername, String yourUsername,boolean isFriend) {
try {
friendList = facebook.getFriends(yourUsername);
if(isFriend){
int index = friendList.indexOf(facebook.getUser(victimUsername));
victimUser = friendList.get(index);
println(victimUser);
}
else
victimUser = facebook.getUser(victimUsername);
try {
birthdayVictimDate.setTime(df.parse(victimUser.getBirthday()));
}
catch(ParseException e) {
e.printStackTrace();
}
victimProfilePic = loadImage(facebook.getPictureURL(victimUsername).toString());
}
catch(FacebookException e) {
e.printStackTrace();
}
}
`
As you can see:
FriendJSONImpl extends UserJSONImpl [id=733939867, name=Tamires Ribeiro, firstName=null, middleName=null, lastName=null, gender=null, locale=null, languages=[], link=null, username=null, thirdPartyId=null, timezone=null, updatedTime=null, verified=null, bio=null, birthday=null, cover=null, education=[], email=null, hometown=null, interestedIn=[], location=null, political=null, favoriteAthletes=[], favoriteTeams=[], picture=null, quotes=null, relationshipStatus=null, religion=null, significantOther=null, videoUploadLimits=null, website=null, work=[]]
If the user isn't a friend of mine I can acess some of those informations, and I get this:
UserJSONImpl [id=733939867, name=Tamires Ribeiro, firstName=Tamires, middleName=null, lastName=Ribeiro, gender=female, locale=pt_BR, languages=[], link=https://www.facebook.com/tamiresribeirodias, username=tamiresribeirodias, thirdPartyId=null, timezone=null, updatedTime=Sat Oct 26 21:20:17 BRST 2013, verified=null, bio=null, birthday=05/13, cover=null, education=[EducationJSONImpl [year=null, type=College, school=IdNameEntityJSONImpl [name=Federal University of Rio de Janeiro, id=109442119074280], degree=null, concentration=[], classes=[], with=[]]], email=null, hometown=null, interestedIn=[], location=null, political=null, favoriteAthletes=[], favoriteTeams=[IdNameEntityJSONImpl [name=Vegetarianos Pensam Melhor, id=240337606020973], IdNameEntityJSONImpl [name=Fluminense Football Club, id=159225040801899]], picture=null, quotes=null, relationshipStatus=In a relationship, religion=null, significantOther=IdNameEntityJSONImpl [name=Pedro Gabriel Lancelloti Pinto, id=100000337547270], videoUploadLimits=null, website=null, work=[]]
As you can see, I can get lot of more informations directly trought facebook wich is confusing because as friend I should get the same or more infomartion.
Does anybody knows why this happen and how it could be solved?
PS: at my app I set on permissions "friends_birthday" and set it also at my user_token.

Related

How to display omdb function returned value in webpage

Can we store the value returned from omdb function searchOneMovie(moviename) so that it can be displayed as output in JSP page when button is clicked? I am developing a Web-Application where on clicking the button I should get the details of movie as searched by user but by using searchOneMovie() I am getting the output in console not in web page. Please tell how to display searchOneMovie() value in JSP page.
CODE:
public void search(HttpServletResponse response, String moviename) throws OmdbSyntaxErrorException, OmdbConnectionErrorException, OmdbMovieNotFoundException, IOException {
Omdb o = new Omdb();
try {
PrintWriter out = response.getWriter();
out.print(o.searchOneMovie(moviename));
} catch (Exception ignore) {
}
}
OUTPUT: This output is coming on console but i wan't it in webpage please help.
Mar 13, 2017 8:13:51 PM com.omdbapi.RestClient execute
INFO: executing GET http://www.omdbapi.com/?t=star+wars HTTP/1.1
Mar 13, 2017 8:13:52 PM com.omdbapi.Omdb resultToJson
INFO: received {"Title":"Star Wars: Episode IV - A New Hope","Year":"1977","Rated":"PG","Released":"25 May 1977","Runtime":"121 min","Genre":"Action, Adventure, Fantasy","Director":"George Lucas","Writer":"George Lucas","Actors":"Mark Hamill, Harrison Ford, Carrie Fisher, Peter Cushing","Plot":"Luke Skywalker joins forces with a Jedi Knight, a cocky pilot, a wookiee and two droids to save the galaxy from the Empire's world-destroying battle-station, while also attempting to rescue Princess Leia from the evil Darth Vader.","Language":"English","Country":"USA","Awards":"Won 6 Oscars. Another 50 wins & 28 nominations.","Poster":"https://images-na.ssl-images-amazon.com/images/M/MV5BYzQ2OTk4N2QtOGQwNy00MmI3LWEwNmEtOTk0OTY3NDk2MGJkL2ltYWdlL2ltYWdlXkEyXkFqcGdeQXVyNjc1NTYyMjg#._V1_SX300.jpg","Metascore":"92","imdbRating":"8.7","imdbVotes":"963,318","imdbID":"tt0076759","Type":"movie","Response":"True"}

How to get country code(calling code) in android?

How can I get Country code of my sim in android code. I have used
TelephonyManager tm = (TelephonyManager)getSystemService(getApplicationContext().TELEPHONY_SERVICE);
String countryCode = tm.getNetworkCountryIso();
But here I get Country name like "BD" for Bangladesh I need +880 for bangladesh.
This code is working like same.
Locale.getDefault().getCountry(); I need code like +91 for ind,+880 for bd.
There is no direct method in the TelephonyManager class which will return you dialing code of country. You have to make a key value pair list for all country.
<string-array name="DialingCountryCode" >
<item>32,BE</item>
<item>501,BZ</item>
<item>229,BJ</item>
<item>975,BT</item>
<item>591,BO</item>
<item>387,BA</item>
<item>267,BW</item>
<item>55,BR</item>
<item>673,BN</item>
<item>359,BG</item>
<item>226,BF</item>
<item>95,MM</item>
<item>257,BI</item>
<item>855,KH</item>
<item>237,CM</item>
<item>1,CA</item>
<item>238,CV</item>
<item>236,CF</item>
<item>235,TD</item>
<item>56,CL</item>
<item>86,CN</item>
<item>61,CX</item>
<item>61,CC</item>
<item>57,CO</item>
<item>269,KM</item>
<item>242,CG</item>
<item>243,CD</item>
<item>682,CK</item>
<item>506,CR</item>
<item>385,HR</item>
<item>53,CU</item>
<item>357,CY</item>
<item>93,AF</item>
<item>355,AL</item>
<item>213,DZ</item>
<item>376,AD</item>
<item>244,AO</item>
<item>672,AQ</item>
<item>54,AR</item>
<item>374,AM</item>
<item>297,AW</item>
<item>61,AU</item>
<item>43,AT</item>
<item>994,AZ</item>
<item>973,BH</item>
<item>880,BD</item>
<item>375,BY</item>
<item>420,CZ</item>
<item>45,DK</item>
<item>253,DJ</item>
<item>670,TL</item>
<item>593,EC</item>
<item>20,EG</item>
<item>503,SV</item>
<item>240,GQ</item>
<item>358,FI</item>
<item>33,FR</item>
<item>291,ER</item>
<item>372,EE</item>
<item>251,ET</item>
<item>500,FK</item>
<item>298,FO</item>
<item>679,FJ</item>
<item>689,PF</item>
<item>241,GA</item>
<item>220,GM</item>
<item>995,GE</item>
<item>49,DE</item>
<item>233,GH</item>
<item>350,GI</item>
<item>30,GR</item>
<item>299,GL</item>
<item>502,GT</item>
<item>224,GN</item>
<item>245,GW</item>
<item>592,GY</item>
<item>509,HT</item>
<item>504,HN</item>
<item>852,HK</item>
<item>36,HU</item>
<item>91,IN</item>
<item>62,ID</item>
<item>98,IR</item>
<item>964,IQ</item>
<item>353,IE</item>
<item>44,IM</item>
<item>972,IL</item>
<item>39,IT</item>
<item>225,CI</item>
<item>81,JP</item>
<item>962,JO</item>
<item>7,KZ</item>
<item>254,KE</item>
<item>686,KI</item>
<item>965,KW</item>
<item>996,KG</item>
<item>856,LA</item>
<item>371,LV</item>
<item>961,LB</item>
<item>266,LS</item>
<item>231,LR</item>
<item>218,LY</item>
<item>423,LI</item>
<item>370,LT</item>
<item>352,LU</item>
<item>853,MO</item>
<item>389,MK</item>
<item>261,MG</item>
<item>265,MW</item>
<item>60,MY</item>
<item>960,MV</item>
<item>223,ML</item>
<item>356,MT</item>
<item>692,MH</item>
<item>222,MR</item>
<item>230,MU</item>
<item>262,YT</item>
<item>52,MX</item>
<item>691,FM</item>
<item>373,MD</item>
<item>377,MC</item>
<item>976,MN</item>
<item>382,ME</item>
<item>212,MA</item>
<item>258,MZ</item>
<item>264,NA</item>
<item>674,NR</item>
<item>977,NP</item>
<item>31,NL</item>
<item>599,AN</item>
<item>687,NC</item>
<item>64,NZ</item>
<item>505,NI</item>
<item>227,NE</item>
<item>234,NG</item>
<item>683,NU</item>
<item>850,KP</item>
<item>47,NO</item>
<item>968,OM</item>
<item>92,PK</item>
<item>680,PW</item>
<item>507,PA</item>
<item>675,PG</item>
<item>595,PY</item>
<item>51,PE</item>
<item>63,PH</item>
<item>870,PN</item>
<item>48,PL</item>
<item>351,PT</item>
<item>1,PR</item>
<item>974,QA</item>
<item>40,RO</item>
<item>7,RU</item>
<item>250,RW</item>
<item>590,BL</item>
<item>685,WS</item>
<item>378,SM</item>
<item>239,ST</item>
<item>966,SA</item>
<item>221,SN</item>
<item>381,RS</item>
<item>248,SC</item>
<item>232,SL</item>
<item>65,SG</item>
<item>421,SK</item>
<item>386,SI</item>
<item>677,SB</item>
<item>252,SO</item>
<item>27,ZA</item>
<item>82,KR</item>
<item>34,ES</item>
<item>94,LK</item>
<item>290,SH</item>
<item>508,PM</item>
<item>249,SD</item>
<item>597,SR</item>
<item>268,SZ</item>
<item>46,SE</item>
<item>41,CH</item>
<item>963,SY</item>
<item>886,TW</item>
<item>992,TJ</item>
<item>255,TZ</item>
<item>66,TH</item>
<item>228,TG</item>
<item>690,TK</item>
<item>676,TO</item>
<item>216,TN</item>
<item>90,TR</item>
<item>993,TM</item>
<item>688,TV</item>
<item>971,AE</item>
<item>256,UG</item>
<item>44,GB</item>
<item>380,UA</item>
<item>598,UY</item>
<item>1,US</item>
<item>998,UZ</item>
<item>678,VU</item>
<item>39,VA</item>
<item>58,VE</item>
<item>84,VN</item>
<item>681,WF</item>
<item>967,YE</item>
<item>260,ZM</item>
<item>263,ZW</item>
</string-array>
public static String getCountryDialCode(){
String contryId = null;
String contryDialCode = null;
TelephonyManager telephonyMngr = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE);
contryId = telephonyMngr.getSimCountryIso().toUpperCase();
String[] arrContryCode=this.getResources().getStringArray(R.array.DialingCountryCode);
for(int i=0; i<arrContryCode.length; i++){
String[] arrDial = arrContryCode[i].split(",");
if(arrDial[1].trim().equals(CountryID.trim())){
contryDialCode = arrDial[0];
break;
}
}
return contryDialCode;
}
Actually libphonenumber is more convenient and is maintained:
PhoneNumberUtil.createInstance(getContext())getCountryCodeForRegion(countryNameCode)
For Android instead of using the Google library this one seems to be more lightweight: https://github.com/MichaelRocks/libphonenumber-android
The Best Way to the Get Country Code is by using this lib.
Get Complete Documentation from Github
This Library can detect country code automatically by just Adding this Attribute app:ccp_autoDetectCountry="true"
Code Example :
<com.hbb20.CountryCodePicker
android:id="#+id/ccp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="8dp"
app:ccp_showFullName="false"
app:ccp_showNameCode="false"
app:ccp_showPhoneCode="true"
app:ccp_autoDetectCountry="true"/>
read Complete Implementation Details from github
https://github.com/hbb20/CountryCodePickerProject

variable always stuck at 1 [duplicate]

This question already has an answer here:
How to use java.util.Scanner to correctly read user input from System.in and act on it?
(1 answer)
Closed 8 years ago.
I have this assignment where I need to populate a 2d array using info from a text file. I am trying to make every thing even using the primekey variable to replace my poscon that I am using temporarily. What is stopping me from doing that is that primekey wont increment right because of another
(MAIN PROBLEM) variable that is stuck, which is the emailcheck variable. I'm pretty sure it has to do with my for loop syntax but I can't quite figure it out.
...
try{
Scanner check = new Scanner(file);
Scanner checkNext = new Scanner(file);
System.out.println("Success File load");
String data=check.next();
System.out.println("data.next() works");
int emailcheck=0;
int primekey=0;
while(check.hasNext()){
posCon++;
//check for # symbol
for(int i=0;i<data.length();i++){
if(data.charAt(i)=='#'){
emailcheck=emailcheck+1;
}
}
//populates position array
if(data.equalsIgnoreCase("staff")||
data.equalsIgnoreCase("freshman")||
data.equalsIgnoreCase("sohmore")||
data.equalsIgnoreCase("junior")||
data.equalsIgnoreCase("senior")||
data.equalsIgnoreCase("adjunct")||
data.equalsIgnoreCase("professor"))
{
db[0][posCon]=data;
sort=1;
data=check.next();
}
//id
else if(sort==1){
db[1][posCon]=data;
sort=2;
data=check.next();
}
//firstname
else if(sort==2){
db[2][posCon]=data;
sort=3;
data=check.next();
}
//lastname
else if(sort==3){
db[3][posCon]=data;
sort=4;
data=check.next();
}
//department
else if(sort==4){
db[4][posCon]=data;
sort=5;
data=check.next();
}
//email
else if(sort==5 && emailcheck==1){
db[5][posCon]=data;
sort=6;
emailcheck=0;
}
else if(sort==5 && emailcheck==0){
db[5][posCon]="not here";
sort=6;
}
//room
else if(sort==6){
db[6][posCon]=data;
sort=0;
data=check.next();
emailcheck=0;
primekey=primekey+1;
System.out.println(primekey);
}
else{
sort=0;
data=check.next();
emailcheck=0;
}
}
}catch(FileNotFoundException e) {
e.printStackTrace();
}
}//End Constructor
here is the data from the text file
Staff 77778 Julie Chang Registrar
Adjunct 19778 Mike Thompson CS mtxxx#gmail.com GITC2400
Staff 30041 Anne Mathews Security
Junior 98444 Serene Murray Math smyyy#gmail.com
Freshman 98772 Bob Mathew CS bmyyy#gmail.com
Professor 19010 Joan Berry Math jbxxx#gmail.com GITC2315C
Professor 19871 Aparna Khat CS akxxx#gmail.com GITC1400
Adjunct 18821 Hari Mentor Physics hmxxx#gmail.com CK231
Staff 20112 Jim George Plant
Junior 68339 Tom Harry CS thyyy#gmail.com
Senior 78883 Vince Charles IT vcyyy#gmail.com
Freshman 87777 Susan Han EE shyyy#gmail.com
Senior 88888 Janki Khat IE jkyyy#gmail.com
Staff 5555 Aparna Sen Plant
Senior 66663 Jill Kaley it jk#jk.com
Staff 77777 Joe Batra plumbing
Staff 33333 Jim Natale Plumbing
You have the data = check.next() call in the wrong place it should just after the start of the loop with the check.hasNext() test in it, and not elsewhere. You only need one Scanner instance the second one you declare is redundant.

sending SMS via a commercial API (trendoo) : nullPointerException

I ask for help because I have a nullpointerexception that I don't understand.
here is the code:
try {
sr = application.launcher.getSmstrend().getConnexion()
.sendSMS(this);
}
} catch (Exception e) {
launcher.append(launcher.format_log.format(new Date())
+ " RDV.envoi : ERREUR d'envoi du message, " + e);
}
to be noted : the getConnexion() method returns a valid object (not null), and the this parameter is also not null. Smstrend is not "trendoo", a site which sends SMS via a java API. The error is :
sam. 11 janv. 2014 22-08-54 RDV.envoi : ERREUR d'envoi du message, java.lang.NullPointerException
can you explain me where to search?where is the null reference?

Writing Excel data to database in Java

This is my method that I use to write excel file data to a database.
public static void executeSQLUpdate(String sql, List<Object> arguments) {
Connection con = null;
PreparedStatement pstmt = null;
try {
con = getConnection(); //a method that returns a java.sql.Connection to your database
System.out.println("\n01)conection :"+con);
pstmt = con.prepareStatement(sql);
System.out.println("\n02)pstn :"+pstmt);
System.out.println( "\n03)arguments size :"+arguments.size());
if (arguments != null) {
int i = 1;
System.out.println( "\n04)if :"+arguments);
for(Object o : arguments) {
System.out.println( "\n05)executeSQLUpdate");
System.out.println( "\n06)object."+o);
System.out.println("\n07)................... :"+i + o);
pstmt.setObject(i, o);
System.out.println("\n08)____________________"+i+o);
}
}
System.out.print("\n09)errorchk........... :");
//method to execute insert, update, delete statements...
pstmt.executeUpdate();
System.out.print("\n10)+++++++++++++++++ :");
} catch(SQLException e) {
System.out.println("\n11)************* :"+e);
//handle the error...
} finally {
//closing the resources (always in finally block, not in the try!)
try {
if (pstmt != null) {
pstmt.close();
}
if (con != null) {
con.close();
}
} catch (SQLException e) {
}
}
}
Up to no 07 all the system out are working. But after that any system out are not working. What is the reason for that? Is there any error in this one?
This is my out put:
run:
AAA BBB CCC
DDD EEE FFF
GGG HHH III
JJJ KKK LLL
MMM NNN OOO
PPP QQQ RRR
01)conection :com.mysql.jdbc.JDBC4Connection#6e70c7
02)pstn :com.mysql.jdbc.JDBC4PreparedStatement#29428e: INSERT INTO files_1 VALUES(** NOT SPECIFIED , NOT SPECIFIED , NOT SPECIFIED **)
03)arguments size :6
04)if :[[AAA, BBB, CCC], [DDD, EEE, FFF], [GGG, HHH, III], [JJJ, KKK, LLL], [MMM, NNN, OOO], [PPP, QQQ, RRR]]
05)executeSQLUpdate :
06)object :[AAA, BBB, CCC]
07)................... :1[AAA, BBB, CCC]
08)__________ :1[AAA, BBB, CCC]
05)executeSQLUpdate :
06)object :[DDD, EEE, FFF]
07)................... :1[DDD, EEE, FFF]
08)__________ :1[DDD, EEE, FFF]
05)executeSQLUpdate :
06)object :[GGG, HHH, III]
07)................... :1[GGG, HHH, III]
08)__________ :1[GGG, HHH, III]
05)executeSQLUpdate :
06)object :[JJJ, KKK, LLL]
07)................... :1[JJJ, KKK, LLL]
08)__________ :1[JJJ, KKK, LLL]
05)executeSQLUpdate :
06)object :[MMM, NNN, OOO]
07)................... :1[MMM, NNN, OOO]
08)__________ :1[MMM, NNN, OOO]
05)executeSQLUpdate :
06)object :[PPP, QQQ, RRR]
07)................... :1[PPP, QQQ, RRR]
08)__________ :1[PPP, QQQ, RRR]
09)errorchk........... :
11)***** :No value specified for parameter 2
java.sql.SQLException: No value specified for parameter 2
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1075)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:989)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:984)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:929)
at com.mysql.jdbc.PreparedStatement.checkAllParametersSet(PreparedStatement.java:2560)
at com.mysql.jdbc.PreparedStatement.fillSendPacket(PreparedStatement.java:2536)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2383)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2327)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2312)
at com.project.bulk.ReadExcelFile.executeSQLUpdate(ReadExcelFile.java:112)
at com.project.bulk.ReadExcelFile.MethodToData(ReadExcelFile.java:138)
at com.project.bulk.ReadExcelFile.main(ReadExcelFile.java:39)
BUILD SUCCESSFUL (total time: 3 seconds)
One error for sure is that you increment i two times!!!
System.out.println("\n07)..................."+i++ + o); // one
pstmt.setObject(i++, o); // two
This means that you don't set the even indices, just the odd ones: 1, 3, 5...
This should correct this error:
System.out.println("\n07)..................."+i + o);
pstmt.setObject(i++, o); // only once, and after the evaluation!
EDIT
*Second, but also big mistake*
} catch(SQLException e) {
System.out.println("\n11)************* :"+e); //WTF?
//handle the error...
}
excuse me for shouting, this has to happen now!
Please, for our and your (future) colleagues' mental health's sake, DO NOT EVER DO THIS AGAIN!
Printing exceptions must happen in one of two ways:
logger.error("message", e);
e.printStackTrace();
As these reserve the stack trace, and thus enable proper debugging of the code
but should never, ever, ever, never! happen in any of these ways:
System.out.print(e)
System.out.print(e.getMessage)
System.out.print("message " + e.getMessage)
logger.error(e.getMessage)
So correctly this should be:
} catch(SQLException e) {
System.out.println("\n11)************* :"+e.getMessage());
e.printStackTrace();
//TODO: handle the error...
}
By the way: using proper logging like log4j is well worth the time! It consumes much more time to clean up all the System.out.*, than to set a proper loglevel...
EDIT2
As for the SQL error:
String sql = "INSERT INTO files_1 VALUES(?)";
This SQL line tells the DBMS that it will have one parameter to deal with. The table has 3 columns, so you need to specify 3 values. Either constants, or parameters (by using ?). So you should have:
String sql = "INSERT INTO files_1 VALUES(?,?,?)";
As indicated by your error
java.sql.SQLException: Invalid argument value: java.io.NotSerializableException
you're trying to set a value with a parameter that's not serializable in this line:
pstmt.setObject(i++, o);
Please make sure that all of your values are either primitives or values that can be mapped to database columns like String or Date.
You can find out which data you're trying to set by putting in a line like this (using a logging framework or System.out.println:
System.out.println("setObject: " + o + ", Class: " + o.getClass());

Categories

Resources