当我拍照时,我收到下面的错误。请注意,该应用程序在 HTC rhyme 和 Galaxy Tab 7.7 上完美运行。如何修复?
08-06 13:18:29.084: E/AndroidRuntime(27803): FATAL EXCEPTION: main
08-06 13:18:29.084: E/AndroidRuntime(27803): java.lang.RuntimeException: Unable to resume activity {ua.mirkvartir.android.frontend/ua.mirkvartir.android.frontend.AddFillActivityApp}: java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=12, result=-1, data=null} to activity {ua.mirkvartir.android.frontend/ua.mirkvartir.android.frontend.AddFillActivityApp}: java.lang.NullPointerException
08-06 13:18:29.084: E/AndroidRuntime(27803): at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2608)
08-06 13:18:29.084: E/AndroidRuntime(27803): at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2636)
08-06 13:18:29.084: E/AndroidRuntime(27803): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2103)
08-06 13:18:29.084: E/AndroidRuntime(27803): at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:3576)
08-06 13:18:29.084: E/AndroidRuntime(27803): at android.app.ActivityThread.access$700(ActivityThread.java:138)
08-06 13:18:29.084: E/AndroidRuntime(27803): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1210)
08-06 13:18:29.084: E/AndroidRuntime(27803): at android.os.Handler.dispatchMessage(Handler.java:99)
08-06 13:18:29.084: E/AndroidRuntime(27803): at android.os.Looper.loop(Looper.java:137)
08-06 13:18:29.084: E/AndroidRuntime(27803): at android.app.ActivityThread.main(ActivityThread.java:4905)
08-06 13:18:29.084: E/AndroidRuntime(27803): at java.lang.reflect.Method.invokeNative(Native Method)
08-06 13:18:29.084: E/AndroidRuntime(27803): at java.lang.reflect.Method.invoke(Method.java:511)
08-06 13:18:29.084: E/AndroidRuntime(27803): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
08-06 13:18:29.084: E/AndroidRuntime(27803): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
08-06 13:18:29.084: E/AndroidRuntime(27803): at dalvik.system.NativeStart.main(Native Method)
08-06 13:18:29.084: E/AndroidRuntime(27803): Caused by: java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=12, result=-1, data=null} to activity {ua.mirkvartir.android.frontend/ua.mirkvartir.android.frontend.AddFillActivityApp}: java.lang.NullPointerException
08-06 13:18:29.084: E/AndroidRuntime(27803): at android.app.ActivityThread.deliverResults(ActivityThread.java:3205)
08-06 13:18:29.084: E/AndroidRuntime(27803): at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2595)
08-06 13:18:29.084: E/AndroidRuntime(27803): ... 13 more
08-06 13:18:29.084: E/AndroidRuntime(27803): Caused by: java.lang.NullPointerException
08-06 13:18:29.084: E/AndroidRuntime(27803): at android.content.ContentResolver.acquireUnstableProvider(ContentResolver.java:1094)
08-06 13:18:29.084: E/AndroidRuntime(27803): at android.content.ContentResolver.query(ContentResolver.java:354)
08-06 13:18:29.084: E/AndroidRuntime(27803): at android.content.ContentResolver.query(ContentResolver.java:313)
08-06 13:18:29.084: E/AndroidRuntime(27803): at android.support.v4.content.CursorLoader.loadInBackground(CursorLoader.java:49)
08-06 13:18:29.084: E/AndroidRuntime(27803): at ua.mirkvartir.android.frontend.AddFillActivityApp.getRealPathFromURI(AddFillActivityApp.java:844)
08-06 13:18:29.084: E/AndroidRuntime(27803): at ua.mirkvartir.android.frontend.AddFillActivityApp.onActivityResult(AddFillActivityApp.java:704)
08-06 13:18:29.084: E/AndroidRuntime(27803): at android.app.Activity.dispatchActivityResult(Activity.java:5492)
08-06 13:18:29.084: E/AndroidRuntime(27803): at android.app.ActivityThread.deliverResults(ActivityThread.java:3201)
forResult 调用
Calendar c = Calendar.getInstance();
ContentValues values = new ContentValues();
values.put(MediaStore.Images.Media.TITLE,
"zdanie " + c.getTime());
mCapturedImageURI = getContentResolver()
.insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
values);
Intent intentPicture = new Intent(
MediaStore.ACTION_IMAGE_CAPTURE);
intentPicture.putExtra(MediaStore.EXTRA_OUTPUT,
mCapturedImageURI);
startActivityForResult(intentPicture, 12);
onResult
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 12 && resultCode == RESULT_OK) {
// photo1 = getRealPathFromURI(mCapturedImageURI);
saveFile(
decodeSampledBitmapFromResource(
getRealPathFromURI(mCapturedImageURI), 800, 800), 1);
pho1.setImageBitmap(decodeSampledBitmapFromResource(
getRealPathFromURI(mCapturedImageURI), 80, 60));
miss1 = 1;
}
}
获取真实路径
public String getRealPathFromURI(Uri contentUri) {
if (contentUri==null){
Log.e("RealPath", "URI: null");
}else Log.e("RealPath", "URI: "+contentUri.toString());
try {
String[] proj = { MediaStore.Images.Media.DATA };
CursorLoader loader = new CursorLoader(getApplicationContext(),
contentUri, proj, null, null, null);
Cursor cursor = loader.loadInBackground();
int column_index = cursor
.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
return cursor.getString(column_index);
} catch (Exception e) {
Log.e("RealPath", e.toString());
e.printStackTrace();
}
return "";
}
来自 realpath 捕获块的 StackTrace
08-06 15:33:23.520: W/System.err(22083): java.lang.NullPointerException
08-06 15:33:23.536: W/System.err(22083): at android.content.ContentResolver.acquireUnstableProvider(ContentResolver.java:1097)
08-06 15:33:23.544: W/System.err(22083): at android.content.ContentResolver.query(ContentResolver.java:357)
08-06 15:33:23.544: W/System.err(22083): at android.content.ContentResolver.query(ContentResolver.java:316)
08-06 15:33:23.544: W/System.err(22083): at android.support.v4.content.CursorLoader.loadInBackground(CursorLoader.java:49)
08-06 15:33:23.544: W/System.err(22083): at ua.mirkvartir.android.frontend.AddFillActivityApp.getRealPathFromURI(AddFillActivityApp.java:842)
08-06 15:33:23.544: W/System.err(22083): at ua.mirkvartir.android.frontend.AddFillActivityApp.onActivityResult(AddFillActivityApp.java:733)
08-06 15:33:23.544: W/System.err(22083): at android.app.Activity.dispatchActivityResult(Activity.java:5436)
08-06 15:33:23.544: W/System.err(22083): at android.app.ActivityThread.deliverResults(ActivityThread.java:3188)
08-06 15:33:23.544: W/System.err(22083): at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2592)
08-06 15:33:23.544: W/System.err(22083): at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2633)
08-06 15:33:23.544: W/System.err(22083): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2100)
08-06 15:33:23.544: W/System.err(22083): at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:3563)
08-06 15:33:23.544: W/System.err(22083): at android.app.ActivityThread.access$700(ActivityThread.java:135)
08-06 15:33:23.544: W/System.err(22083): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1207)
08-06 15:33:23.544: W/System.err(22083): at android.os.Handler.dispatchMessage(Handler.java:99)
08-06 15:33:23.552: W/System.err(22083): at android.os.Looper.loop(Looper.java:137)
08-06 15:33:23.552: W/System.err(22083): at android.app.ActivityThread.main(ActivityThread.java:4849)
08-06 15:33:23.552: W/System.err(22083): at java.lang.reflect.Method.invokeNative(Native Method)
08-06 15:33:23.552: W/System.err(22083): at java.lang.reflect.Method.invoke(Method.java:511)
08-06 15:33:23.552: W/System.err(22083): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:795)
08-06 15:33:23.559: W/System.err(22083): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:562)
08-06 15:33:23.559: W/System.err(22083): at dalvik.system.NativeStart.main(Native Method)
编辑我在另外 5 部手机上进行了测试,一切正常。只有 LG 手机会导致问题。 编辑:我尝试使用游标加载器而不是托管查询。同样的问题