使用此功能,我只能从图库加载图片,但无法从文件系统或 Dropbox 上传图片,或从相机获取图片:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode != RESULT_OK) return;
switch (requestCode) {
case PICK_FROM_CAMERA:
this.picturePath = picturePath;
Intent intent1 = new Intent(getBaseContext(), AndroidPaint.class);
startActivity(intent1);
break;
case PICK_FROM_FILE:
Uri selectedImage = data.getData();
String[] filePathColumn = {MediaStore.Images.Media.DATA};
Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String picturePath = cursor.getString(columnIndex);
this.picturePath = picturePath;
cursor.close();
Intent intent = new Intent(getBaseContext(), AndroidPaint.class);
startActivity(intent);
// doCrop();
break;
}
}
如果有人有建议请帮助我,我想上传所有设置的图片。
问题在这里:
java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=3, result=-1, data=Intent { dat=file:///mnt/sdcard/Android/data/com.dropbox.android/files/scratch/appSetpaint4fun.png typ=image/png }} to activity {com.slikar.slika/slikar.Main.FirstPage}: java.lang.NullPointerException at android.app.ActivityThread.deliverResults(ActivityThread.java:3103) at android.app.ActivityThread.handleSendResult(ActivityThread.java:3146) at android.app.ActivityThread.access$1100(ActivityThread.java:132) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1187) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:137) at android.app.ActivityThread.main(ActivityThread.java:4575) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:511) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556) at dalvik.system.NativeStart.main(Native Method) Caused by: java.lang.NullPointerException at slikar.Main.FirstPage.onActivityResult(FirstPage.java:396) at android.app.Activity.dispatchActivityResult(Activity.java:4649) at android.app.ActivityThread.deliverResults(ActivityThread.java:3099) ... 11 more
错误在这部分代码中:
Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null, null, null);
cursor.moveToFirst();