0
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
這是我選擇視頻後得到的錯誤消息。這個應用程序的流程是....我點擊文件上傳按鈕,一個對話框彈出瀏覽按鈕,上傳按鈕和一些必填字段(名稱,說明,標籤等)。點擊瀏覽按鈕後會顯示filechooser窗口。瀏覽按鈕的文本將被替換爲文件名。有時候這種工作很好,但有時會給我一個錯誤。android-nullpointerexception當從文件選擇器返回時
我已經做了一些研究和人工智能說,這是由於缺乏內存,而有人說這是因爲我試圖做btnBrowse.setText(filename)
之前,對話框準備好後,從filechooser回來。有沒有什麼辦法可以讓監聽器監聽對話框是否準備好進行編輯?如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
向我們顯示您的代碼。同時發佈完整的錯誤堆棧可能會有幫助。 – Piovezan
即時通訊不好格式化...我盡我所能 – user1865027
錯誤不會經常發生。我一旦得到它就會在這裏發佈。你能告訴我的代碼錯了嗎? – user1865027