In my app i am trying to retrieve the data from a fb graph api url as below
URL fbmsg = new URL("https://graph.facebook.com/"+FbPostId()+"?access_token="+TOKEN+"");
URLConnection yc = fbmsg.openConnection();
BufferedReader in = new BufferedReader(new InputStreamReader(yc.getInputStream()));
String inputLine;
String s = "";
while ((inputLine = in.readLine()) != null)
System.out.println(inputLine);
//Log.d(TAG, "getPostId trace getFbPostId " + inputLine);
s = s + inputLine + "n";
//Log.d(TAG, "getPostId trace getFbPostId " + s);
in.close();
//System.out.println(s);
JSONObject json = new JSONObject(inputLine);
//JSONObject message = json.getJSONObject("message");
String fbmessage = json.getString("message");
System.out.println( "message: " + fbmessage );
i am getting the output in json format but i am unable to read the message , getting error at this line JSONObject json = new JSONObject(inputLine);
getting nullpointer exception . below is my log
01-28 14:05:56.384: E/FBUtils(5894): getPostId
01-28 14:05:56.384: E/FBUtils(5894): java.lang.NullPointerException
01-28 14:05:56.384: E/FBUtils(5894): at org.json.JSONTokener.nextCleanInternal(JSONTokener.java:116)
01-28 14:05:56.384: E/FBUtils(5894): at org.json.JSONTokener.nextValue(JSONTokener.java:94)
01-28 14:05:56.384: E/FBUtils(5894): at org.json.JSONObject.<init>(JSONObject.java:154)
01-28 14:05:56.384: E/FBUtils(5894): at org.json.JSONObject.<init>(JSONObject.java:171)
01-28 14:05:56.384: E/FBUtils(5894): at org.appright.myneighborhood.utils.FBUtils.doInBackground(FBUtils.java:104)
01-28 14:05:56.384: E/FBUtils(5894): at org.appright.myneighborhood.utils.FBUtils.doInBackground(FBUtils.java:1)
Any help is appreciated.
printlnis executed inside the while, until inputLine isnull.. therefore theNullPointerException