简体   繁体   中英

Error after post message on wall Facebook

I'm currently running this error on 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)

The error happen right after I posted message on Wall. I use activity.finish() right after I make that toast..

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

The message run "posted successfully" which indicate I'm done sharing to Facebook..

The application then force close, I've been searching the solution for hours...

Can someone help me?

EDIT: Here's my callback response code, it's begin at line 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);
            }

I have to disable toast first, then notify pop-up to next activity

It seems that your Toast is missing context. Try using getApplicationContext() instead of getActivity() .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM