0

I am trying to figure out was is wrong here, I am building a form for users to be able to upload a profile picture. When clicking the button it takes you to the android gallery (would like to let the user take a picture right then and there) but once a picture is selected the app crashes not sure why but I think the error is pointing to the line with the method below for getRealPathFromURI(currImageURI) I have tried searching for different solutions but they seem to show the same response of how to do this... Like this How to get the Full file path from URI http://monstercoda.wordpress.com/2012/04/15/android-image-upload-tutorial-part-i/

The code:

@Override
        public void onActivityResult(int requestCode, int resultCode, Intent data) {
            if(resultCode == RESULT_OK) {
                if(requestCode == 1) {
                              Uri currImageURI = data.getData();
                    Log.d("The path","Current image path is ---->" + getRealPathFromURI(currImageURI));
                    TextView tv_path = (TextView) findViewById(R.id.path);
                    tv_path.setText(getRealPathFromURI(currImageURI));

                }
            }
        }

        public String getRealPathFromURI(Uri contentUri) {
            String res = null;
            String[] proj={MediaStore.Images.Media.DATA};
            Cursor cursor = getContentResolver().query(contentUri,proj, null, null, null);
            if(cursor.moveToFirst()) {
                int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
                res = cursor.getString(column_index);
            }
            cursor.close();
            return res;
        }

The Error:

12-22 16:25:38.894: E/AndroidRuntime(19577): FATAL EXCEPTION: main
12-22 16:25:38.894: E/AndroidRuntime(19577): Process: com.fslio, PID: 19577
12-22 16:25:38.894: E/AndroidRuntime(19577): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1, result=-1, data=Intent { dat=content://com.google.android.apps.docs.storage/document/acc=1;doc=172 flg=0x1 }} to activity {com.fslio/com.fslio.wardrobe}: java.lang.IllegalArgumentException: Unknown column requested: _data
12-22 16:25:38.894: E/AndroidRuntime(19577):    at android.app.ActivityThread.deliverResults(ActivityThread.java:3346)
12-22 16:25:38.894: E/AndroidRuntime(19577):    at android.app.ActivityThread.handleSendResult(ActivityThread.java:3389)
12-22 16:25:38.894: E/AndroidRuntime(19577):    at android.app.ActivityThread.access$1200(ActivityThread.java:135)
12-22 16:25:38.894: E/AndroidRuntime(19577):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1445)
12-22 16:25:38.894: E/AndroidRuntime(19577):    at android.os.Handler.dispatchMessage(Handler.java:102)
12-22 16:25:38.894: E/AndroidRuntime(19577):    at android.os.Looper.loop(Looper.java:137)
12-22 16:25:38.894: E/AndroidRuntime(19577):    at android.app.ActivityThread.main(ActivityThread.java:4998)
12-22 16:25:38.894: E/AndroidRuntime(19577):    at java.lang.reflect.Method.invokeNative(Native Method)
12-22 16:25:38.894: E/AndroidRuntime(19577):    at java.lang.reflect.Method.invoke(Method.java:515)
12-22 16:25:38.894: E/AndroidRuntime(19577):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:777)
12-22 16:25:38.894: E/AndroidRuntime(19577):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:593)
12-22 16:25:38.894: E/AndroidRuntime(19577):    at dalvik.system.NativeStart.main(Native Method)
12-22 16:25:38.894: E/AndroidRuntime(19577): Caused by: java.lang.IllegalArgumentException: Unknown column requested: _data
12-22 16:25:38.894: E/AndroidRuntime(19577):    at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:167)
12-22 16:25:38.894: E/AndroidRuntime(19577):    at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:137)
12-22 16:25:38.894: E/AndroidRuntime(19577):    at android.content.ContentProviderProxy.query(ContentProviderNative.java:413)
12-22 16:25:38.894: E/AndroidRuntime(19577):    at android.content.ContentResolver.query(ContentResolver.java:461)
12-22 16:25:38.894: E/AndroidRuntime(19577):    at android.content.ContentResolver.query(ContentResolver.java:404)
12-22 16:25:38.894: E/AndroidRuntime(19577):    at com.fslio.wardrobe.getRealPathFromURI(wardrobe.java:80)
12-22 16:25:38.894: E/AndroidRuntime(19577):    at com.fslio.wardrobe.onActivityResult(wardrobe.java:67)
12-22 16:25:38.894: E/AndroidRuntime(19577):    at android.app.Activity.dispatchActivityResult(Activity.java:5435)
12-22 16:25:38.894: E/AndroidRuntime(19577):    at android.app.ActivityThread.deliverResults(ActivityThread.java:3342)
12-22 16:25:38.894: E/AndroidRuntime(19577):    ... 11 more
1
  • Try this link! . It might help. Commented Dec 3, 2014 at 18:26

1 Answer 1

4

Yes , Issue is in getRealPathFromURI inside the onActivityResult,

Error is ,

Caused by: java.lang.IllegalArgumentException: Unknown column requested: _data
com.fslio.wardrobe.getRealPathFromURI(wardrobe.java:80)
com.fslio.wardrobe.onActivityResult(wardrobe.java:67)

Debug your code you are getting problem in data while you selecting the image.

For more details check this reference link.

Sign up to request clarification or add additional context in comments.

4 Comments

Nice I like your post, going to check it out, do you also, share on how to serve the image to the backend servers so it can be stored for seeing the picture show up when on any device?
Also, where are you getting Utility from in your post?
let me know if you have any query ,and make green mark if this answer is helpful to you
I was trying to connect your tutorial to my current code, how do I include your picture_selection class in my onClickListener for my button, I was trying this but it crashes the app... Intent intent = new Intent(myClass.this, Picture_Selection.class); startActivity(intent);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.