简体   繁体   English

Android问题与创建图像上传

[英]Android issue with creating image upload

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/ 当单击按钮时,它会将您带到android画廊(希望让用户立即在那儿拍照),但是一旦选择了照片,应用程序便崩溃了,不知道为什么,但是我认为错误指向的是getRealPathFromURI(currImageURI)的以下方法我尝试搜索不同的解决方案,但它们似乎显示出如何执行此操作的相同响应...像这样如何从URI http://monstercoda.wordpress.com 获取完整文件路径 / 2012/04/15 /机器人图像上传教程部分-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

Yes , Issue is in getRealPathFromURI inside the onActivityResult , 是的,问题在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. 有关更多详细信息,请参见此参考链接。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM