我一直在使用攝像頭在我的Android應用程序應用程序崩潰時,按後退按鈕在Android相機意向
我有保存數據的格式問題,還有就是按鈕拍照用相機,從拍攝的圖像相機將放置在我的表單中的ImageView上。
有關於調用攝像頭的意圖,並把圖像的形式
我的問題是沒有問題的: 在相機應用, 如果我按返回鍵(返回形式)我的應用程序崩潰。
爲什麼?
這是對我的按鈕調用攝像頭代碼
btn_takepic.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent, CAMERA_PIC_REQUEST);
}
});
這是我的onActivityResult
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
final EditText et_foto = (EditText) findViewById(R.id.et_foto);
if(requestCode == CAMERA_PIC_REQUEST) {
Bitmap thumbnail = (Bitmap) data.getExtras().get("data");
ImageView image = (ImageView) findViewById(R.id.imv_foto);
image.setImageBitmap(thumbnail);
//toastkeun(data.getExtras().get("data").toString());
}
super.onActivityResult(requestCode, resultCode, data);
}
我在真實設備 測試,這是我的logcat
07-08 16:05:26.187: ERROR/AndroidRuntime(12116): FATAL EXCEPTION: main
07-08 16:05:26.187: ERROR/AndroidRuntime(12116): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=2, result=0, data=null} to activity {com.ngimagrid.nigmago/com.ngimagrid.nigmago.FormAsetTambah}: java.lang.NullPointerException
07-08 16:05:26.187: ERROR/AndroidRuntime(12116): at android.app.ActivityThread.deliverResults(ActivityThread.java:3515)
07-08 16:05:26.187: ERROR/AndroidRuntime(12116): at android.app.ActivityThread.handleSendResult(ActivityThread.java:3557)
07-08 16:05:26.187: ERROR/AndroidRuntime(12116): at android.app.ActivityThread.access$2800(ActivityThread.java:125)
07-08 16:05:26.187: ERROR/AndroidRuntime(12116): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2063)
07-08 16:05:26.187: ERROR/AndroidRuntime(12116): at android.os.Handler.dispatchMessage(Handler.java:99)
07-08 16:05:26.187: ERROR/AndroidRuntime(12116): at android.os.Looper.loop(Looper.java:123)
07-08 16:05:26.187: ERROR/AndroidRuntime(12116): at android.app.ActivityThread.main(ActivityThread.java:4627)
07-08 16:05:26.187: ERROR/AndroidRuntime(12116): at java.lang.reflect.Method.invokeNative(Native Method)
07-08 16:05:26.187: ERROR/AndroidRuntime(12116): at java.lang.reflect.Method.invoke(Method.java:521)
07-08 16:05:26.187: ERROR/AndroidRuntime(12116): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
07-08 16:05:26.187: ERROR/AndroidRuntime(12116): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
07-08 16:05:26.187: ERROR/AndroidRuntime(12116): at dalvik.system.NativeStart.main(Native Method)
07-08 16:05:26.187: ERROR/AndroidRuntime(12116): Caused by: java.lang.NullPointerException
07-08 16:05:26.187: ERROR/AndroidRuntime(12116): at com.ngimagrid.nigmago.FormAsetTambah.onActivityResult(FormAsetTambah.java:246)
07-08 16:05:26.187: ERROR/AndroidRuntime(12116): at android.app.Activity.dispatchActivityResult(Activity.java:3890)
07-08 16:05:26.187: ERROR/AndroidRuntime(12116): at android.app.ActivityThread.deliverResults(ActivityThread.java:3511)
07-08 16:05:26.187: ERROR/AndroidRuntime(12116): ... 11 more
07-08 16:05:26.187: ERROR/AndroidRuntime(12116): FATAL EXCEPTION: main
07-08 16:05:26.187: ERROR/AndroidRuntime(12116): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=2, result=0, data=null} to activity {com.ngimagrid.nigmago/com.ngimagrid.nigmago.FormAsetTambah}: java.lang.NullPointerException
07-08 16:05:26.187: ERROR/AndroidRuntime(12116): at android.app.ActivityThread.deliverResults(ActivityThread.java:3515)
07-08 16:05:26.187: ERROR/AndroidRuntime(12116): at android.app.ActivityThread.handleSendResult(ActivityThread.java:3557)
07-08 16:05:26.187: ERROR/AndroidRuntime(12116): at android.app.ActivityThread.access$2800(ActivityThread.java:125)
07-08 16:05:26.187: ERROR/AndroidRuntime(12116): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2063)
07-08 16:05:26.187: ERROR/AndroidRuntime(12116): at android.os.Handler.dispatchMessage(Handler.java:99)
07-08 16:05:26.187: ERROR/AndroidRuntime(12116): at android.os.Looper.loop(Looper.java:123)
07-08 16:05:26.187: ERROR/AndroidRuntime(12116): at android.app.ActivityThread.main(ActivityThread.java:4627)
07-08 16:05:26.187: ERROR/AndroidRuntime(12116): at java.lang.reflect.Method.invokeNative(Native Method)
07-08 16:05:26.187: ERROR/AndroidRuntime(12116): at java.lang.reflect.Method.invoke(Method.java:521)
07-08 16:05:26.187: ERROR/AndroidRuntime(12116): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
07-08 16:05:26.187: ERROR/AndroidRuntime(12116): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
07-08 16:05:26.187: ERROR/AndroidRuntime(12116): at dalvik.system.NativeStart.main(Native Method)
07-08 16:05:26.187: ERROR/AndroidRuntime(12116): Caused by: java.lang.NullPointerException
07-08 16:05:26.187: ERROR/AndroidRuntime(12116): at com.ngimagrid.nigmago.FormAsetTambah.onActivityResult(FormAsetTambah.java:246)
07-08 16:05:26.187: ERROR/AndroidRuntime(12116): at android.app.Activity.dispatchActivityResult(Activity.java:3890)
07-08 16:05:26.187: ERROR/AndroidRuntime(12116): at android.app.ActivityThread.deliverResults(ActivityThread.java:3511)
07-08 16:05:26.187: ERROR/AndroidRuntime(12116): ... 11 more
從這一行,我認爲這是問題...
07-08 16:05:26.187: ERROR/AndroidRuntime(12116): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=2, result=0, data=null} to activity {com.ngimagrid.nigmago/com.ngimagrid.nigmago.FormAsetTambah}: java.lang.NullPointerException
沒有結果返回正確嗎? 如何解決這個問題?
感謝
cmiiw
data.getExtras()。get(「data」); 這條線在各種設備上有一些問題。 http://code.google.com/p/android/issues/detail?id=1480 對於某些設備,數據不隨包返回。我不記得哪些設備。但是,即使您獲得了位圖,分辨率也非常低。 –