0

我正在使用一个名为注销的按钮。此注销适用于应用程序中用户的 facebook 注销选项。当我单击此按钮时,出现以下错误。

我在下面的代码中注释了出现此错误的行。

09-11 15:25:30.124: E/AndroidRuntime(6866): FATAL EXCEPTION: main
> 09-11 15:25:30.124: E/AndroidRuntime(6866):
> java.lang.NullPointerException 09-11 15:25:30.124:
> E/AndroidRuntime(6866):   at
> com.example.settings.Settings$1.logout(Settings.java:46) 09-11
> 15:25:30.124: E/AndroidRuntime(6866):     at
> com.example.settings.Settings$1.onClick(Settings.java:38) 09-11
> 15:25:30.124: E/AndroidRuntime(6866):     at
> android.view.View.performClick(View.java:2485) 09-11 15:25:30.124:
> E/AndroidRuntime(6866):   at
> android.view.View$PerformClick.run(View.java:9080) 09-11 15:25:30.124:
> E/AndroidRuntime(6866):   at
> android.os.Handler.handleCallback(Handler.java:587) 09-11
> 15:25:30.124: E/AndroidRuntime(6866):     at
> android.os.Handler.dispatchMessage(Handler.java:92) 09-11
> 15:25:30.124: E/AndroidRuntime(6866):     at
> android.os.Looper.loop(Looper.java:123) 09-11 15:25:30.124:
> E/AndroidRuntime(6866):   at
> android.app.ActivityThread.main(ActivityThread.java:3683) 09-11
> 15:25:30.124: E/AndroidRuntime(6866):     at
> java.lang.reflect.Method.invokeNative(Native Method) 09-11
> 15:25:30.124: E/AndroidRuntime(6866):     at
> java.lang.reflect.Method.invoke(Method.java:507) 09-11 15:25:30.124:
> E/AndroidRuntime(6866):   at
> com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
> 09-11 15:25:30.124: E/AndroidRuntime(6866):   at
> com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597) 09-11
> 15:25:30.124: E/AndroidRuntime(6866):     at
> dalvik.system.NativeStart.main(Native Method)

我的代码:

脸书脸书;

Button btn_logout = (Button)findViewById(R.id.logout);
               btn_logout.setOnClickListener(new View.OnClickListener() {

        public  void onClick(View v) {
            // TODO Auto-generated method stub
            String response = logout();//error
            Toast.makeText(getApplicationContext(), "Logout"+ response , 2).show();
        }

        public String logout() {
            // TODO Auto-generated method stub
            String res = null;
            try {
                  res = fb.logout(getApplicationContext());//error

            } catch (MalformedURLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            return res;
        }


    });
4

2 回答 2

0

确保Facebook对象(fb)已初始化...

Facebook fb= new ....
于 2012-09-11T10:09:12.160 回答
-1

您可能忘记初始化 Facebook fb

Facebook fb= new Facebook("APP_ID");
于 2012-09-11T10:07:22.690 回答