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