Question

When, I take photo I recieve error below. Note that app works perfectly on HTC rhyme and galaxy tab 7.7. How It can be fixed?

    08-06 13:18:29.084: E/AndroidRuntime(27803): FATAL EXCEPTION: main
08-06 13:18:29.084: E/AndroidRuntime(27803): java.lang.RuntimeException: Unable to resume activity {ua.mirkvartir.android.frontend/ua.mirkvartir.android.frontend.AddFillActivityApp}: java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=12, result=-1, data=null} to activity {ua.mirkvartir.android.frontend/ua.mirkvartir.android.frontend.AddFillActivityApp}: java.lang.NullPointerException
08-06 13:18:29.084: E/AndroidRuntime(27803):    at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2608)
08-06 13:18:29.084: E/AndroidRuntime(27803):    at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2636)
08-06 13:18:29.084: E/AndroidRuntime(27803):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2103)
08-06 13:18:29.084: E/AndroidRuntime(27803):    at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:3576)
08-06 13:18:29.084: E/AndroidRuntime(27803):    at android.app.ActivityThread.access$700(ActivityThread.java:138)
08-06 13:18:29.084: E/AndroidRuntime(27803):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1210)
08-06 13:18:29.084: E/AndroidRuntime(27803):    at android.os.Handler.dispatchMessage(Handler.java:99)
08-06 13:18:29.084: E/AndroidRuntime(27803):    at android.os.Looper.loop(Looper.java:137)
08-06 13:18:29.084: E/AndroidRuntime(27803):    at android.app.ActivityThread.main(ActivityThread.java:4905)
08-06 13:18:29.084: E/AndroidRuntime(27803):    at java.lang.reflect.Method.invokeNative(Native Method)
08-06 13:18:29.084: E/AndroidRuntime(27803):    at java.lang.reflect.Method.invoke(Method.java:511)
08-06 13:18:29.084: E/AndroidRuntime(27803):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
08-06 13:18:29.084: E/AndroidRuntime(27803):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
08-06 13:18:29.084: E/AndroidRuntime(27803):    at dalvik.system.NativeStart.main(Native Method)
08-06 13:18:29.084: E/AndroidRuntime(27803): Caused by: java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=12, result=-1, data=null} to activity {ua.mirkvartir.android.frontend/ua.mirkvartir.android.frontend.AddFillActivityApp}: java.lang.NullPointerException
08-06 13:18:29.084: E/AndroidRuntime(27803):    at android.app.ActivityThread.deliverResults(ActivityThread.java:3205)
08-06 13:18:29.084: E/AndroidRuntime(27803):    at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2595)
08-06 13:18:29.084: E/AndroidRuntime(27803):    ... 13 more
08-06 13:18:29.084: E/AndroidRuntime(27803): Caused by: java.lang.NullPointerException
08-06 13:18:29.084: E/AndroidRuntime(27803):    at android.content.ContentResolver.acquireUnstableProvider(ContentResolver.java:1094)
08-06 13:18:29.084: E/AndroidRuntime(27803):    at android.content.ContentResolver.query(ContentResolver.java:354)
08-06 13:18:29.084: E/AndroidRuntime(27803):    at android.content.ContentResolver.query(ContentResolver.java:313)
08-06 13:18:29.084: E/AndroidRuntime(27803):    at android.support.v4.content.CursorLoader.loadInBackground(CursorLoader.java:49)
08-06 13:18:29.084: E/AndroidRuntime(27803):    at ua.mirkvartir.android.frontend.AddFillActivityApp.getRealPathFromURI(AddFillActivityApp.java:844)
08-06 13:18:29.084: E/AndroidRuntime(27803):    at ua.mirkvartir.android.frontend.AddFillActivityApp.onActivityResult(AddFillActivityApp.java:704)
08-06 13:18:29.084: E/AndroidRuntime(27803):    at android.app.Activity.dispatchActivityResult(Activity.java:5492)
08-06 13:18:29.084: E/AndroidRuntime(27803):    at android.app.ActivityThread.deliverResults(ActivityThread.java:3201)

forResult call

Calendar c = Calendar.getInstance();
                                ContentValues values = new ContentValues();
                                values.put(MediaStore.Images.Media.TITLE,
                                        "zdanie " + c.getTime());
                                mCapturedImageURI = getContentResolver()
                                        .insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
                                                values);
                                Intent intentPicture = new Intent(
                                        MediaStore.ACTION_IMAGE_CAPTURE);
                                intentPicture.putExtra(MediaStore.EXTRA_OUTPUT,
                                        mCapturedImageURI);
                                startActivityForResult(intentPicture, 12);

onResult

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == 12 && resultCode == RESULT_OK) {
            // photo1 = getRealPathFromURI(mCapturedImageURI);
            saveFile(
                    decodeSampledBitmapFromResource(
                            getRealPathFromURI(mCapturedImageURI), 800, 800), 1);
            pho1.setImageBitmap(decodeSampledBitmapFromResource(
                    getRealPathFromURI(mCapturedImageURI), 80, 60));
            miss1 = 1;

        } 
}

getRealPath

   public String getRealPathFromURI(Uri contentUri) {
        if (contentUri==null){
            Log.e("RealPath", "URI: null");
        }else Log.e("RealPath", "URI: "+contentUri.toString());
        try {
            String[] proj = { MediaStore.Images.Media.DATA };
            CursorLoader loader = new CursorLoader(getApplicationContext(),
                    contentUri, proj, null, null, null);
            Cursor cursor = loader.loadInBackground();
            int column_index = cursor
                    .getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
            cursor.moveToFirst();
            return cursor.getString(column_index);
        } catch (Exception e) {
            Log.e("RealPath", e.toString());
            e.printStackTrace();
        }
        return "";
    }

StackTrace from realpath catch block

   08-06 15:33:23.520: W/System.err(22083): java.lang.NullPointerException
08-06 15:33:23.536: W/System.err(22083):    at android.content.ContentResolver.acquireUnstableProvider(ContentResolver.java:1097)
08-06 15:33:23.544: W/System.err(22083):    at android.content.ContentResolver.query(ContentResolver.java:357)
08-06 15:33:23.544: W/System.err(22083):    at android.content.ContentResolver.query(ContentResolver.java:316)
08-06 15:33:23.544: W/System.err(22083):    at android.support.v4.content.CursorLoader.loadInBackground(CursorLoader.java:49)
08-06 15:33:23.544: W/System.err(22083):    at ua.mirkvartir.android.frontend.AddFillActivityApp.getRealPathFromURI(AddFillActivityApp.java:842)
08-06 15:33:23.544: W/System.err(22083):    at ua.mirkvartir.android.frontend.AddFillActivityApp.onActivityResult(AddFillActivityApp.java:733)
08-06 15:33:23.544: W/System.err(22083):    at android.app.Activity.dispatchActivityResult(Activity.java:5436)
08-06 15:33:23.544: W/System.err(22083):    at android.app.ActivityThread.deliverResults(ActivityThread.java:3188)
08-06 15:33:23.544: W/System.err(22083):    at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2592)
08-06 15:33:23.544: W/System.err(22083):    at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2633)
08-06 15:33:23.544: W/System.err(22083):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2100)
08-06 15:33:23.544: W/System.err(22083):    at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:3563)
08-06 15:33:23.544: W/System.err(22083):    at android.app.ActivityThread.access$700(ActivityThread.java:135)
08-06 15:33:23.544: W/System.err(22083):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1207)
08-06 15:33:23.544: W/System.err(22083):    at android.os.Handler.dispatchMessage(Handler.java:99)
08-06 15:33:23.552: W/System.err(22083):    at android.os.Looper.loop(Looper.java:137)
08-06 15:33:23.552: W/System.err(22083):    at android.app.ActivityThread.main(ActivityThread.java:4849)
08-06 15:33:23.552: W/System.err(22083):    at java.lang.reflect.Method.invokeNative(Native Method)
08-06 15:33:23.552: W/System.err(22083):    at java.lang.reflect.Method.invoke(Method.java:511)
08-06 15:33:23.552: W/System.err(22083):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:795)
08-06 15:33:23.559: W/System.err(22083):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:562)
08-06 15:33:23.559: W/System.err(22083):    at dalvik.system.NativeStart.main(Native Method)

EDIT I made test on 5 more phones and evrything works fine. Only LG phone cause problem. EDIT: I tried to use cursor loader instead of managed queries. Same problemms

Was it helpful?

Solution

if you are wondering why it works without any problems on some devices, and some devices not:

as you probably see - the camera app is not the same app. in fact, each camera app is entirely different, even the ones coming with your stock.

what's to this and your problem? - no one prevents applications that reacts to MediaStore.ACTION_IMAGE_CAPTURE ignoring completely the MediaStore.EXTRA_OUTPUT intent extra.

your code assume that the application been selected by the user (or the default camera app installed) will store for sure the captured image in the path specified. unfortionatly, I know from experience that it not always true.

sad but true. you can't count on MediaStore.EXTRA_OUTPUT if you think your users would use such camera apps, or specific devices like the LG series default camera app.

in this case, maybe you could get the image by the approach suggested by @Arun C Thomas,but as I sad - getData() not necessarily brings you anything also, if the camera app did not stored the data itself in the result.

that's why you must varify null, or doing some "try/catch" to prevent your app from crashing on this cases...

OTHER TIPS

mostly the Cursor returned is null so it is crashing when you are trying to get the column_index.

Cursor cursor = managedQuery(contentUri, proj, null, null, null);
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top