我正在写一个标准的应用程序,拍摄照片,然后将其保存到手机,一旦我点击保存按钮,它保存图像,但崩溃与强制关闭,我在这里阅读至少10-15个线程同样的问题,但没有一个帮助。我正在测试三星Galaxy S
这是意图
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
imageFilePath = Environment.getExternalStorageDirectory().getAbsolutePath() + "/picture.jpg";
File imageFile = new File(imageFilePath);
Uri imageFileUri = Uri.fromFile(imageFile);
cameraIntent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT,imageFileUri );
startActivityForResult(cameraIntent, 1337);
也是OnActivity
protected void onActivityResult (int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == CAMERA_REQUEST && resultCode == RESULT_OK)
{
BitmapFactory.Options bmpFactoryOptions = new BitmapFactory.Options();
bmpFactoryOptions.inJustDecodeBounds = false;
Bitmap bmp = BitmapFactory.decodeFile(imageFilePath, bmpFactoryOptions);
image.setImageBitmap(bmp);
}
}
提前致谢
这是LogCat
06-21 13:07:09.421: D/AndroidRuntime(18525): Shutting down VM 06-21 13:07:09.421: W/dalvikvm(18525): threadid=1: thread exiting with uncaught exception (group=0x40018578) 06-21 13:07:09.421: E/AndroidRuntime(18525): FATAL EXCEPTION: main 06-21 13:07:09.421: E/AndroidRuntime(18525): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1337, result=-1, data=null} to activity {com.example.testnewbutton/com.example.testnewbutton.MainActivity}: java.lang.NullPointerException 06-21 13:07:09.421: E/AndroidRuntime(18525): at android.app.ActivityThread.deliverResults(ActivityThread.java:2536) 06-21 13:07:09.421: E/AndroidRuntime(18525): at android.app.ActivityThread.handleSendResult(ActivityThread.java:2578) 06-21 13:07:09.421: E/AndroidRuntime(18525): at android.app.ActivityThread.access$2000(ActivityThread.java:117) 06-21 13:07:09.421: E/AndroidRuntime(18525): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:965) 06-21 13:07:09.421: E/AndroidRuntime(18525): at android.os.Handler.dispatchMessage(Handler.java:99) 06-21 13:07:09.421: E/AndroidRuntime(18525): at android.os.Looper.loop(Looper.java:130) 06-21 13:07:09.421: E/AndroidRuntime(18525): at android.app.ActivityThread.main(ActivityThread.java:3687) 06-21 13:07:09.421: E/AndroidRuntime(18525): at java.lang.reflect.Method.invokeNative(Native Method) 06-21 13:07:09.421: E/AndroidRuntime(18525): at java.lang.reflect.Method.invoke(Method.java:507) 06-21 13:07:09.421: E/AndroidRuntime(18525): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867) 06-21 13:07:09.421: E/AndroidRuntime(18525): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625) 06-21 13:07:09.421: E/AndroidRuntime(18525): at dalvik.system.NativeStart.main(Native Method) 06-21 13:07:09.421: E/AndroidRuntime(18525): Caused by: java.lang.NullPointerException
答案 0 :(得分:0)
如果没有看到你的LogCat,很难说是什么问题。但是,看起来你正在用相机拍照并以全分辨率加载它。 Galaxy S配备500万像素摄像头。
<(>((2592 * 1944 * 32)/ 8)/ 1024)/ 1024 = 19.22 MB。您可能遇到OutOfMemoryError。看看here,了解如何避免这种情况。