NullPointerException , while trying to retrieve values from JSON object , usin facebook graph api?
I am trying to retrieve values from Json Object but getting Exception.I am trying to fetch my facebook profile info , using facebook graph api.
ProfileRequestListner.java
public void onComplete(final String response, final Object state)
{
try
{
// process the response here: executed in background thread
Log.d("Facebook-Example", "Response: " + response.toString());
JSONObject json = Util.parseJson(response);
final String name = json.getString("name");
Bundle b = new Bundle();
b.putString(SoapboxApplication.FIRST_NAME, name);
// b.putString(SoapboxApplication.LAST_NAME,last_name);
com.android.soapbox.SoapboxApplication.mListener.**ProfileInfoAvailable**(b);
}
catch (JSONException e)
{
Log.w("Facebook-Example", "JSON Error in response");
Log.e("Facebook-Example", "JSON Error in response"+e.fillInStackTrace());
}
catch (FacebookError e)
{
Log.w("Facebook-Example", "Facebook Error: " + e.getMessage());
}
}
ProfileInfoAvailable(Bundle b) is defined as
public class ProfileInfoListner extends Activity implements ProfileEventListener
{
public EditText mFirstNameTextBox ;
public TextView mLastNameTextBox;
public void ProfileInfoAvailable(Bundle b)
{
Log.e("Facebook-Example", "HGGGGGGGGGGGGGGGGGGG");
try
{
for (String key : b.keySet())
{
if开发者_如何学编程(key.compareTo(SoapboxApplication.FIRST_NAME) == 0)
{
Log.e("Facebook-Example", "IIIIFFFFFFFFFFFFFFF");
//Assuming mFirstNameTextBox points to the textbox on PRofile screen
mFirstNameTextBox.setText(b.getString(key));
}
else if(key.compareTo(SoapboxApplication.LAST_NAME) == 0)
{
//Assuming mLastNameTextBox points to the textbox on Profile screen
mLastNameTextBox.setText(b.getString(key));
}
}
}
catch(NullPointerException c)
{
Log.e("EEEEERRROOROROROORR",""+c.fillInStackTrace());
}
}
}
What wrong with that.?? Any help would be highly appropriated.
What is null is the EditText mFirstNameTextBox
(and the following TextView
) also, since you are not initializing them to anything as I can see.
If you are defining those in an XML file, use a LayoutInflater
and the method findViewById()
to obtain the reference to those resources.
精彩评论