NullPointerException,在尝试从JSON对象中检索值时,使用facebook graph api?

时间:2011-06-17 12:00:21

标签: java android json

我正在尝试从Json对象中检索值但得到Exception。我正在尝试使用facebook graph api获取我的Facebook个人资料信息。

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)定义为

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());
}

}   
}

那有什么不对。 任何帮助都会被高度挪用。

1 个答案:

答案 0 :(得分:1)

什么是null,EditText mFirstNameTextBox(以及以下TextView)也是如此,因为您没有将它们初始化为我能看到的任何内容。

如果要在XML文件中定义这些文件,请使用LayoutInflater和方法findViewById()获取对这些资源的引用。