Android 未能传递结果ResultInfo{who=null,request=100,result=-1,data=Intent

Android 未能传递结果ResultInfo{who=null,request=100,result=-1,data=Intent,android,android-intent,nullpointerexception,android-implicit-intent,Android,Android Intent,Nullpointerexception,Android Implicit Intent,当我从多媒体资料中选择视频时,我很少出现以下异常- Fatal Exception: java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=100, result=-1, data=Intent { dat=content://com.estrongs.files/storage/emulated/0/ADM/720P_1500K_152999072.mp }} to activity

当我从多媒体资料中选择视频时,我很少出现以下异常-

Fatal Exception: java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=100, result=-1, data=Intent { dat=content://com.estrongs.files/storage/emulated/0/ADM/720P_1500K_152999072.mp }} to activity {xyzMainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.String.contains(java.lang.CharSequence)' on a null object reference
       at android.app.ActivityThread.deliverResults(ActivityThread.java)
       at android.app.ActivityThread.handleSendResult(ActivityThread.java)
       at android.app.ActivityThread.access$1500(ActivityThread.java)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java)
       at android.os.Handler.dispatchMessage(Handler.java)
       at android.os.Looper.loop(Looper.java)
       at android.app.ActivityThread.main(ActivityThread.java)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java)
       at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:102)

Caused by java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.String.contains(java.lang.CharSequence)' on a null object reference
       at android.content.ContentResolver.checkLeakDetectIgnoreList(ContentResolver.java)
       at android.content.ContentResolver.openTypedAssetFileDescriptor(ContentResolver.java)
       at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java)
       at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java)
       at android.media.MediaPlayer.setDataSource(MediaPlayer.java)
       at android.widget.VideoView.openVideo(VideoView.java)
       at android.widget.VideoView.setVideoURI(VideoView.java)
       at android.widget.VideoView.setVideoURI(VideoView.java)
       at xyz.onActivityResult(Unknown Source)
       at android.app.Activity.dispatchActivityResult(Activity.java)
       at android.app.ActivityThread.deliverResults(ActivityThread.java)
下面是我正在使用的代码:

private void uploadVideo() {
    try {
        Intent intent = new Intent();
        intent.setType("video/*");
        intent.setAction(Intent.ACTION_GET_CONTENT);
        startActivityForResult(Intent.createChooser(intent, "Select Video"), REQUEST_TAKE_GALLERY_VIDEO);
    } catch (Exception e) {

    }
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (resultCode == RESULT_OK) {
        if (requestCode == REQUEST_TAKE_GALLERY_VIDEO) {
            selectedVideoUri = data.getData();
            videoView.setVideoURI(selectedVideoUri);
            videoView.start();
        }
    }
}
在访问数据之前,我检查
onActivityResult
中的
resultCode
,无法理解为什么会出现此异常。

尝试更改此异常

if (resultCode == RESULT_OK) {

由java.lang.NullPointerException引起:尝试对空对象引用调用虚拟方法“boolean java.lang.String.contains(java.lang.CharSequence)”

这是实现该问题的主要例外

位于android.widget.VideoView.setVideoURI(VideoView.java)

问题就在这里:

selectedVideoUri=data.getData()

videoView.setVideoURI(selectedVideoUri)


因为你的数据是空的。

哪个异常?你至少得到了两个!
NullPointerException
@greenapps我得到了两个。第一个是由第二个引起的。谷歌是你的朋友。
从图库上传视频时-
。上传?我看不到上传的代码。@greenapps在问题中更新。。我的意思是在从图库中选择视频时加载到VideoView应该是“data!=null”还是“data.getData()!=null”?@varmashrivastava try如果数据为null,那么为什么会出现异常显示-
data=Intent{dat=content://com.estrongs.files/storage/emulated/0/ADM/720P_1500K_152999072.mp }}到活动{xyzMainActivity}:
如何防止is异常?如果(resultCode==RESULT\u OK&&data!=null)我应该更新到
吗?是的,你应该添加null检查以防止空引用。类似
数据!=空
如果数据为空,那么为什么异常显示-
data=Intent{dat=content://com.estrongs.files/storage/emulated/0/ADM/720P_1500K_152999072.mp }}到活动{xyzMainActivity}:
 if (resultCode == RESULT_OK && data.getData()!=null) {