捕获照片时出错(LinearLayout中的NullPointerException)

时间:2013-01-08 05:38:24

标签: android android-camera

我正在使用Intent在我的应用程序中捕获照片:

Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent, CAMERA_REQUEST);

但是当我拍摄照片并单击“保存”按钮时,它会抛出错误:

liblog              failed to call dumpstate
AndroidRuntime      java.lang.NullPointerException
AndroidRuntime      at android.widget.LinearLayout.layoutHorizontal(LinearLayout.java:1210)
AndroidRuntime      at android.widget.TableRow.onLayout(TableRow.java:121)       
AndroidRuntime      at android.view.View.layout(View.java:7175)
AndroidRuntime      at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1254)
AndroidRuntime      at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1130)
AndroidRuntime      at android.widget.TableLayout.onLayout(TableLayout.java:440)
AndroidRuntime      at android.view.View.layout(View.java:7175)
AndroidRuntime      at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
AndroidRuntime      at android.widget.ScrollView.onLayout(ScrollView.java:1565)
AndroidRuntime      at android.view.View.layout(View.java:7175)
AndroidRuntime      at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1254)
AndroidRuntime      at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1130)
AndroidRuntime      at android.widget.LinearLayout.onLayout(Lin1earLayout.java:1047)
AndroidRuntime      at android.view.View.layout(View.java:7175)
AndroidRuntime      at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
AndroidRuntime      at android.view.View.layout(View.java:7175)
AndroidRuntime      at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1254)
AndroidRuntime      at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1130)
AndroidRuntime      at android.widget.LinearLayout.onLayout(LinearLayout.java:1047)
AndroidRuntime      at android.view.View.layout(View.java:7175)
AndroidRuntime      at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
AndroidRuntime      at android.view.View.layout(View.java:7175)
AndroidRuntime      at android.view.ViewRoot.performTraversals(ViewRoot.java:1146)
AndroidRuntime      at android.view.ViewRoot.handleMessage(ViewRoot.java:1865)
AndroidRuntime      at android.os.Handler.dispatchMessage(Handler.java:99)
AndroidRuntime      at android.os.Looper.loop(Looper.java:130)     
AndroidRuntime      at android.app.ActivityThread.main(ActivityThread.java:3687)
AndroidRuntime      at java.lang.reflect.Method.invokeNative(Native Method)          
AndroidRuntime      at java.lang.reflect.Method.invoke(Method.java:507)       
AndroidRuntime      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
AndroidRuntime      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
AndroidRuntime      at dalvik.system.NativeStart.main(Native Method)
                    Dumpstate > /data/log/dumpstate_app_error

但是当我将这个应用程序用于不同的移动设备时,它可以完美地运行。 我不知道是什么问题。

拍摄照片后的代码:

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    try {
        if (requestCode == CAMERA_REQUEST) {

            Bitmap bitmap = (Bitmap) data.getExtras().get("data");
            imageViewPhoto.setImageBitmap(bitmap);

        }

    } catch (NullPointerException e) {
        Toast.makeText(this, "Problem while capturing photo. Try after some time.", Toast.LENGTH_LONG).show();
    }
}

0 个答案:

没有答案