谁可以帮我解决这个错误。
例外情况如下:
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()
中收到结果。添加I call present Fragment继续......
有时它发生在异常之上。我不知道如何解决这个错误。
代码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。
答案 0 :(得分: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);