在Facebook上发布消息后出错

时间:2013-10-22 12:10:14

标签: android facebook

我目前正在LogCat上运行此错误

10-22 18:58:43.449: E/AndroidRuntime(8521): FATAL EXCEPTION: main
10-22 18:58:43.449: E/AndroidRuntime(8521): java.lang.NullPointerException
10-22 18:58:43.449: E/AndroidRuntime(8521):     at android.widget.Toast.<init>(Toast.java:92)
10-22 18:58:43.449: E/AndroidRuntime(8521):     at android.widget.Toast.makeText(Toast.java:238)
10-22 18:58:43.449: E/AndroidRuntime(8521):     at com.sevenskylab.karapansapi.MainFragment$2.onCompleted(MainFragment.java:145)
10-22 18:58:43.449: E/AndroidRuntime(8521):     at com.facebook.Request$4.run(Request.java:1669)
10-22 18:58:43.449: E/AndroidRuntime(8521):     at android.os.Handler.handleCallback(Handler.java:615)
10-22 18:58:43.449: E/AndroidRuntime(8521):     at android.os.Handler.dispatchMessage(Handler.java:92)
10-22 18:58:43.449: E/AndroidRuntime(8521):     at android.os.Looper.loop(Looper.java:137)
10-22 18:58:43.449: E/AndroidRuntime(8521):     at android.app.ActivityThread.main(ActivityThread.java:4745)
10-22 18:58:43.449: E/AndroidRuntime(8521):     at java.lang.reflect.Method.invokeNative(Native Method)
10-22 18:58:43.449: E/AndroidRuntime(8521):     at java.lang.reflect.Method.invoke(Method.java:511)
10-22 18:58:43.449: E/AndroidRuntime(8521):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
10-22 18:58:43.449: E/AndroidRuntime(8521):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
10-22 18:58:43.449: E/AndroidRuntime(8521):     at dalvik.system.NativeStart.main(Native Method)

错误发生在我在Wall上发布消息后。 我做完吐司后立即使用activity.finish()。

Toast.makeText(getActivity(), "Message posted succesfully", Toast.LENGTH_SHORT).show();
getActivity().finish();

消息运行“已成功发布”,表明我已完成与Facebook分享..

应用程序然后强制关闭,我一直在寻找解决方案几个小时......

有人可以帮助我吗?

编辑:这是我的回调响应代码,它从第145行开始。

    @Override
            public void onCompleted(Response response) 
            {
                FacebookRequestError error = response.getError();

                if (error != null){
                    //Toast.makeText(getActivity() , error.getErrorMessage(), Toast.LENGTH_SHORT).show();
                    //getActivity().finish();
                    Cocos2dxHelper.setStringForKey("messageCB",  error.getErrorMessage());
                }
                else{

//                  getActivity().runOnUiThread(new runnable(){
//                      public void run(){
//                          Log.d("UI thread", "I am the UI thread");
//                      }
//                  });
                    //Toast.makeText(getActivity(), "Message posted succesfully", Toast.LENGTH_SHORT).show();
                    //getActivity().finish();
                    Cocos2dxHelper.setStringForKey("messageCB",  "Message posted succesfully");
                }

                //getApplicationContext().finish();

                getActivity().finish();
                Log.i("cocos2d-x debug info", Cocos2dxHelper.getStringForKey("messageCB", "unknown"));
                AndroidNDKHelper.SendMessageWithParameters("Share", null);
            }

我必须先禁用吐司,然后通知弹出到下一个活动

1 个答案:

答案 0 :(得分:0)

您的Toast似乎缺少上下文。尝试使用getApplicationContext()代替getActivity()