0

我目前在 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)

我在墙上发布消息后立即发生错误。我做完吐司后立即使用 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);
            }

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

4

1 回答 1

0

看来您Toast缺少上下文。尝试使用getApplicationContext()而不是getActivity().

于 2013-10-22T12:21:44.223 回答