Ich habe eine ziemlich einfache App, die die Kamera aus einem Menü startet. Die Kamera startet gut, aber wenn ich ok traf nach einer Aufnahme erhalte ich eine NPE auf meinem Nexus One:Ich bekomme eine NullPointerException, wenn ich ACTION_IMAGE_CAPTURE verwende, um ein Bild zu machen
E/AndroidRuntime(3891): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=0, result=-1, data=null} to activity {net.asplode.tr/net.asplode.tr.PostImage}: java.lang.NullPointerException
E/AndroidRuntime(3891): at android.app.ActivityThread.deliverResults(ActivityThread.java:3515)
E/AndroidRuntime(3891): at android.app.ActivityThread.handleSendResult(ActivityThread.java:3557)
E/AndroidRuntime(3891): at android.app.ActivityThread.access$2800(ActivityThread.java:125)
E/AndroidRuntime(3891): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2063)
E/AndroidRuntime(3891): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(3891): at android.os.Looper.loop(Looper.java:123)
E/AndroidRuntime(3891): at android.app.ActivityThread.main(ActivityThread.java:4627)
E/AndroidRuntime(3891): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(3891): at java.lang.reflect.Method.invoke(Method.java:521)
E/AndroidRuntime(3891): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
E/AndroidRuntime(3891): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
E/AndroidRuntime(3891): at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime(3891): Caused by: java.lang.NullPointerException
E/AndroidRuntime(3891): at net.asplode.tr.PostImage.onActivityResult(PostImage.java:92)
E/AndroidRuntime(3891): at android.app.Activity.dispatchActivityResult(Activity.java:3890)
E/AndroidRuntime(3891): at android.app.ActivityThread.deliverResults(ActivityThread.java:3511)
E/AndroidRuntime(3891): ... 11 more
W/ActivityManager( 85): Force finishing activity net.asplode.tr/.PostImage
Code:
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == R.id.mnuCamera) {
Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
ContentValues values = new ContentValues();
values.put(Media.TITLE, "image");
Uri tempPhotoUri = getContentResolver().insert(Media.EXTERNAL_CONTENT_URI, values);
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, tempPhotoUri);
startActivityForResult(cameraIntent, FROM_CAMERA);
return true;
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode != RESULT_OK) {
return;
}
Uri imageUri = data.getData();
Log.i("imageUri: ", imageUri.toString());
}
In onActivityResult(), wenn die Absicht null ist, dann, wie der ImagePath @sheridan – Abhi
@nsheridan bekommen - Sorry, auf die Mühe zu machen Eine alte Frage, ich habe das gleiche Problem, aber ich werde wirklich verrückt, weil ich es nicht zur Arbeit bringen kann. Könnten Sie bitte etwas Code posten, um Ihre Lösung zu zeigen? – Matteo