【发布时间】:2018-08-22 09:38:33
【问题描述】:
从图库中选择视频时,我很少遇到异常-
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,因此无法理解为什么会出现此异常。
【问题讨论】:
-
哪个例外?你至少有两个!
NullPointerException. -
@greenapps 我得到了两个..第一个由第二个引起
-
Google 是你的朋友。
-
while uploading video from gallery-。上传?我没有看到上传的代码。 -
@greenapps 在问题中更新..我的意思是从图库中选择视频并上传到 videoview
标签: android android-intent nullpointerexception android-implicit-intent