facebook安卓崩溃

时间:2012-11-26 11:04:43

标签: android facebook facebook-android-sdk

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

以上是 onComplete() 方法中的代码。

我得到回复“https://graph.facebook.com/me?access_token= * *** *这是完美的,当我在浏览器中输入它我收到json响应但facebook sdk Util.class崩溃是logcat错误。

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)     

请让我知道是什么问题。谢谢你。

2 个答案:

答案 0 :(得分: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();
        }

答案 1 :(得分:0)

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

try {
                            json = Util.parseJson(fb.request("me"));
                        } catch (NullPointException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        }