java.lang.RuntimeException: Unable to resume activity {com.myactivity}: java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=2, result=-1, data=Intent { dat=content://media/external/video/media/20101 typ=video/mp4 (has extras) }} to activity {com.myactivity}: java.lang.NullPointerException
这是我选择视频后收到的错误消息。这个应用程序的流程是......我点击文件上传按钮,弹出一个带有浏览按钮的对话框,一个上传按钮和几个必填字段(名称,描述,标签等)。单击浏览按钮后会显示一个文件选择器窗口。浏览按钮的文本将被文件名替换。有时这项工作非常好,但有时会给我一个错误。
我做了一些研究,有人说这是由于内存不足,而有些人说这是因为我试图btnBrowse.setText(filename)
在从文件选择器返回后对话框准备好之前做。如果对话准备好进行编辑,有什么方法可以让我有一个监听器来监听?喜欢的if(dialog.isShowing())
方法。但我不知道把这张支票放在哪里......
有人可以帮忙吗?(如果有人有内存不足的解决方案,也请指教。)谢谢!
btnBrowse = (Button) dialVideoUpload.findViewById(R.id.btnBrowseVideo);
btnUpload = (Button) dialVideoUpload.findViewById(R.id.btnUpload);
btnBrowse.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
createVideoIntent();
}
});
private void createVideoIntent(){
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("video/*");
Intent chooser = createVideoChooserIntent(createVideoFromCameraIntent());
chooser.putExtra(Intent.EXTRA_INTENT, intent);
startActivityForResult(chooser, FILECHOOSER_REQUESTCODE_VIDEO);
}
private Intent createVideoChooserIntent(Intent... intents) {
Intent chooser = new Intent(Intent.ACTION_CHOOSER);
chooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, intents);
chooser.putExtra(Intent.EXTRA_TITLE, "Please Choose Your Video");
return chooser;
}
private Intent createVideoFromCameraIntent() {
return new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
switch (requestCode) {
case FILECHOOSER_REQUESTCODE_VIDEO:
if (resultCode == Activity.RESULT_OK) {
String[] projection = { MediaStore.Images.Media.DATA, MediaStore.Video.Media.SIZE, MediaStore.Video.Media.DURATION, MediaStore.Video.Media.TITLE };
Cursor cursor = managedQuery(intent.getData(), projection, null, null, null);
cursor.moveToFirst();
String filePath = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Video.Media.DATA));
String fileName = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Video.Media.TITLE));
int fileSize = cursor.getInt(cursor.getColumnIndexOrThrow(MediaStore.Video.Media.SIZE));
long duration = TimeUnit.MILLISECONDS.toSeconds(cursor.getInt(cursor.getColumnIndexOrThrow(MediaStore.Video.Media.DURATION)));
System.out.println("path: " + filePath);
System.out.println("name: " + fileName);
System.out.println("size: " + fileSize);
System.out.println("duration: " + duration);
// btnBrowse.setText(fileName); <---this is where I got error
}
break;
}
}
下面是错误信息。
06-12 10:09:46.445: E/AndroidRuntime(31965): FATAL EXCEPTION: main
06-12 10:09:46.445: E/AndroidRuntime(31965): java.lang.RuntimeException: Unable to resume activity {com.myactivity/com.myactivity.Webviewer}: java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=2, result=-1, data=Intent { dat=content://media/external/video/media/20101 typ=video/mp4 (has extras) }} to activity {com. myactivity /com. myactivity.Webviewer}: java.lang.NullPointerException
06-12 10:09:46.445: E/AndroidRuntime(31965): at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2812)
06-12 10:09:46.445: E/AndroidRuntime(31965): at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2851)
06-12 10:09:46.445: E/AndroidRuntime(31965): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2234)
06-12 10:09:46.445: E/AndroidRuntime(31965): at android.app.ActivityThread.access$600(ActivityThread.java:139)
06-12 10:09:46.445: E/AndroidRuntime(31965): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1261)
06-12 10:09:46.445: E/AndroidRuntime(31965): at android.os.Handler.dispatchMessage(Handler.java:99)
06-12 10:09:46.445: E/AndroidRuntime(31965): at android.os.Looper.loop(Looper.java:154)
06-12 10:09:46.445: E/AndroidRuntime(31965): at android.app.ActivityThread.main(ActivityThread.java:4945)
06-12 10:09:46.445: E/AndroidRuntime(31965): at java.lang.reflect.Method.invokeNative(Native Method)
06-12 10:09:46.445: E/AndroidRuntime(31965): at java.lang.reflect.Method.invoke(Method.java:511)
06-12 10:09:46.445: E/AndroidRuntime(31965): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
06-12 10:09:46.445: E/AndroidRuntime(31965): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
06-12 10:09:46.445: E/AndroidRuntime(31965): at dalvik.system.NativeStart.main(Native Method)
06-12 10:09:46.445: E/AndroidRuntime(31965): Caused by: java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=2, result=-1, data=Intent { dat=content://media/external/video/media/20101 typ=video/mp4 (has extras) }} to activity {com. myactivity /com. myactivity.Webviewer}: java.lang.NullPointerException
06-12 10:09:46.445: E/AndroidRuntime(31965): at android.app.ActivityThread.deliverResults(ActivityThread.java:3387)
06-12 10:09:46.445: E/AndroidRuntime(31965): at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2793)
06-12 10:09:46.445: E/AndroidRuntime(31965): ... 12 more
06-12 10:09:46.445: E/AndroidRuntime(31965): Caused by: java.lang.NullPointerException
06-12 10:09:46.445: E/AndroidRuntime(31965): at com. myactivity.Webviewer.onActivityResult(Webviewer.java:853)
06-12 10:09:46.445: E/AndroidRuntime(31965): at android.app.Activity.dispatchActivityResult(Activity.java:4740)
06-12 10:09:46.445: E/AndroidRuntime(31965): at android.app.ActivityThread.deliverResults(ActivityThread.java:3383)
06-12 10:09:46.445: E/AndroidRuntime(31965): ... 13 more