我从fabric.io那里得到了很多时间。但是我的测试没有在我的手机上发生任何故障,所以我并没有找到解决方案这个错误。
我很快从图库中选择图像,然后用户裁剪此图像并将此文件资源设置为imageview。
我也使用这个裁剪图像库。 https://github.com/lvillani/android-cropimage
我从那里打电话
profileImage.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivityForResult(MediaStoreUtils.getPickImageIntent(MainActivity.this), REQUEST_PICTURE);
}
});
public static Intent getPickImageIntent(final Context context) {
final Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
return Intent.createChooser(intent, "Select picture");
}
的onCreate
File Folder = new File(Environment.getExternalStorageDirectory() + "/folder/");
croppedImageFile = new File(Environment.getExternalStorageDirectory() + "/folder/test.jpg");
if (!Folder.exists()) {
Folder.mkdirs();
File noMedia = new File(Environment.getExternalStorageDirectory() + "/folder" + "/.nomedia");
try {
noMedia.createNewFile();
croppedImageFile.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}
onActivityResult
protected void onActivityResult(int requestCode, int resultCode,
Intent imageReturnedIntent) {
super.onActivityResult(requestCode, resultCode, imageReturnedIntent);
if ((requestCode == REQUEST_PICTURE) && (resultCode == RESULT_OK)) {
Uri croppedImage = Uri.fromFile(croppedImageFile);
CropImageIntentBuilder cropImage = new CropImageIntentBuilder(200, 200, croppedImage);
cropImage.setOutlineColor(0xFF03A9F4);
cropImage.setSourceImage(imageReturnedIntent.getData());
startActivityForResult(cropImage.getIntent(this), REQUEST_CROP_PICTURE);
} else if ((requestCode == REQUEST_CROP_PICTURE) && (resultCode == RESULT_OK)) {
profileImage.setImageBitmap(BitmapFactory.decodeFile(croppedImageFile.getAbsolutePath()));
profileImage.setTag(Constants.IMAGE_IS_DEFINED);
}
崩溃报告
java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=2, result=-1, data=Intent { act=file:///storage/sdcard0/folder/test.jpg (has extras) }} to activity {com.example.app/com.example.app.MainActivity}: java.lang.NullPointerException
at android.app.ActivityThread.deliverResults(ActivityThread.java:3209)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:3252)
at android.app.ActivityThread.access$1200(ActivityThread.java:143)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1289)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4960)
at java.lang.reflect.Method.invokeNative(Method.java)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
at dalvik.system.NativeStart.main(NativeStart.java)
Caused by: java.lang.NullPointerException
at com.example.app.MainActivity.onActivityResult()
at android.app.Activity.dispatchActivityResult(Activity.java:5387)
at android.app.ActivityThread.deliverResults(ActivityThread.java:3205)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:3252)
at android.app.ActivityThread.access$1200(ActivityThread.java:143)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1289)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4960)
at java.lang.reflect.Method.invokeNative(Method.java)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
at dalvik.system.NativeStart.main(NativeStart.java)
答案 0 :(得分:0)
好像你没有正确设置结果代码:
ResultInfo{who=null, request=2, result=-1, data=Intent { act=file:///storage/sdcard0/folder/test.jpg (has extras) }}
result=-1
通常表示错误,因此无论您在何处调用Intent
,都可能出错。
也许你没有设定最好的结果。你必须这样做:
setResult(Activity.RESULT_OK, yourData);
who=null
似乎Activity
发回的结果是null
,但它确实没有多大意义。