1

谁能帮我解决这个错误。

例外如下:

java.lang.RuntimeException: Unable to resume activity {com.demo.project/com.demo.project.view.main.PersonActivity}: java.lang.RuntimeException: Failure delivering result ResultInfo{who=android:fragment:2, request=998, result=-1, data=null} to activity {com.demo.project/com.demo.project.view.main.PersonActivity}: java.lang.NullPointerException
--------- Stack trace ---------
android.app.ActivityThread.performResumeActivity(ActivityThread.java:2458)
android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2486)
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2000)
android.app.ActivityThread.access$600(ActivityThread.java:128)
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1161)
android.os.Handler.dispatchMessage(Handler.java:99)
android.os.Looper.loop(Looper.java:137)
android.app.ActivityThread.main(ActivityThread.java:4514)
java.lang.reflect.Method.invokeNative(Native Method)
java.lang.reflect.Method.invoke(Method.java:511)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
dalvik.system.NativeStart.main(Native Method)  
java.lang.RuntimeException: Failure delivering result ResultInfo{who=android:fragment:2, request=998, result=-1, data=null} to activity {com.viettel.vinamilk/com.viettel.vinamilk.view.main.SalesPersonActivity}: java.lang.NullPointerException
android.app.ActivityThread.deliverResults(ActivityThread.java:2994)
android.app.ActivityThread.performResumeActivity(ActivityThread.java:2445)
android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2486)
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2000)
android.app.ActivityThread.access$600(ActivityThread.java:128)
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1161)
android.os.Handler.dispatchMessage(Handler.java:99)
android.os.Looper.loop(Looper.java:137)
android.app.ActivityThread.main(ActivityThread.java:4514)
java.lang.reflect.Method.invokeNative(Native Method)
java.lang.reflect.Method.invoke(Method.java:511)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
dalvik.system.NativeStart.main(Native Method)

我的项目包括一个主要活动,并在活动中添加了许多片段。从相机拍照时,接收结果onActivityResult()。添加我调用当前片段继续...

有时它会发生在异常之上。我不知道如何解决这个错误。

代码在onAcitivtyResult: -

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    String filePath = "";
    switch (requestCode) {
    case MyActivity.RQ_SALE_TAKE_PHOTO:
        {
            if (resultCode == RESULT_OK) {
                if (data != null && data.getExtras() != null && data.getAction() != null) {
                    Bitmap tempBitmap = null;
                    tempBitmap = (Bitmap) data.getExtras().get("data");
                    MyFragment fragment = (MyFragment) this.getFragmentManager()
                            .findFragmentByTag(MyFragment.TAG);
                    if(fragment != null){
                        fragment.executePicture(data);
                    }
                }
            } else {
                //DO SOMETHING HERE
            }
        }
        break;
    }
}

谁能帮我解释一下上述错误,以及如何解决这个错误。TIA。

4

1 回答 1

0

那么我有同样的问题。有时将数据从相机传送到您的文件需要时间。如果您在确保数据准备就绪之前继续工作,则可能会发生此问题!有一个简单的方法。你可以等

final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
                        @Override
                        public void run() {
                            if(data == null)
                                handler.postDelayed(this, 1000);
                            else {
                                // do actions
                                //condition = true;
                            }
                        }
                    }, 1000); 
于 2020-01-29T09:08:13.397 回答