1

我正在使用 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();
    }
}
4

0 回答 0