Pergunta

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

this is the error message I got after I chose a video. the flow of this app is....I click on file upload button, a dialog pop out with a browse button, an upload button and a couple required fields(name, description, tag, etc). A filechooser window is shown after I clicked on the browse button. the text of the browse button will be replaced by the filename. Sometimes this work perfectly fine but sometimes gives me an error.

I've done some research and ppl said that this is due to the lack of memory while some people said this is because I tried to do btnBrowse.setText(filename) before the dialog is ready after coming back from filechooser. Is there any way I can have a listener that listens if dialog is ready for editing? like if(dialog.isShowing()) method. but i dont know where to put this check...

Can someone please help?? (if anyone has the solution for lack of memory, please advice too.) Thanks!!

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;
    }
}

below is the error message.

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
Foi útil?

Solução

problem solved. I took the advice from Danita over here, and it worked!!

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top