0
JSONObject json = null;
                            try {
                                json = Util.parseJson(fb.request("me"));
                            } catch (MalformedURLException e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                            } catch (JSONException e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                            } catch (IOException e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                            } catch (FacebookError e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                            }     

Above is the code within onComplete() method.

I get response "https://graph.facebook.com/me?access_token=****"* which is perfect when I enter it in browser I receive json response but facebook sdk Util.class crashes below is the logcat error.

FATAL EXCEPTION: main
java.lang.NullPointerException
at libcore.net.http.HttpEngine.writeRequestHeaders(HttpEngine.java:625)
at libcore.net.http.HttpEngine.readResponse(HttpEngine.java:771)
at libcore.net.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:274)
at libcore.net.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:168)
at libcore.net.http.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:270)
at com.facebook.android.Util.openUrl(Util.java:211)
at com.facebook.android.Facebook.requestImpl(Facebook.java:790)
    at com.facebook.android.Facebook.request(Facebook.java:717)
    at com.example.check5.MainActivity$1$1.onComplete(MainActivity.java:112)
    at com.facebook.android.Facebook.onSessionCallback(Facebook.java:331)
    at com.facebook.android.Facebook.access$11(Facebook.java:312)
    at com.facebook.android.Facebook$1.call(Facebook.java:291)
    at com.facebook.Session$3$1.run(Session.java:1316)
    at android.os.Handler.handleCallback(Handler.java:605)
    at android.os.Handler.dispatchMessage(Handler.java:92)
    at android.os.Looper.loop(Looper.java:154)
    at android.app.ActivityThread.main(ActivityThread.java:4945)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
    at dalvik.system.NativeStart.main(Native Method)     

Please let me know what is the problem.Thanks in Advance.

4

2 回答 2

0

尝试在代码中添加空点异常

try {
                            json = Util.parseJson(fb.request("me"));
                        } catch (NullPointException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        }
于 2012-11-26T12:15:18.907 回答
0
 Bundle b = new Bundle();
    b.putString("access_token", facebookManager.mFacebook.getAccessToken());
    b.putString("query", "SELECT name FROM user WHERE uid = me()");

    try {
        String myResult = Util.openUrl("https://api.facebook.com/method/fql.query", "GET", b);
            Log.i("MyResult", myResult);
        } catch (MalformedURLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
于 2012-11-26T11:24:19.057 回答