1

カメラ ビューをセットアップしようとしていますが、アプリでエラーが発生します。ここでの問題はカメラ ID にあると思います。カメラ ID を取得する方法がわかりません。

04-10 16:59:03.374: E/AndroidRuntime(19562): FATAL EXCEPTION: main
04-10 16:59:03.374: E/AndroidRuntime(19562): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.petkovski.mk/com.petkovski.mk.TransparentSmsActivity}: java.lang.NullPointerException
04-10 16:59:03.374: E/AndroidRuntime(19562):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1768)
04-10 16:59:03.374: E/AndroidRuntime(19562):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1784)
04-10 16:59:03.374: E/AndroidRuntime(19562):    at android.app.ActivityThread.access$1500(ActivityThread.java:123)
04-10 16:59:03.374: E/AndroidRuntime(19562):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:939)
04-10 16:59:03.374: E/AndroidRuntime(19562):    at android.os.Handler.dispatchMessage(Handler.java:99)
04-10 16:59:03.374: E/AndroidRuntime(19562):    at android.os.Looper.loop(Looper.java:130)
04-10 16:59:03.374: E/AndroidRuntime(19562):    at android.app.ActivityThread.main(ActivityThread.java:3835)
04-10 16:59:03.374: E/AndroidRuntime(19562):    at java.lang.reflect.Method.invokeNative(Native Method)
04-10 16:59:03.374: E/AndroidRuntime(19562):    at java.lang.reflect.Method.invoke(Method.java:507)
04-10 16:59:03.374: E/AndroidRuntime(19562):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:847)
04-10 16:59:03.374: E/AndroidRuntime(19562):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:605)
04-10 16:59:03.374: E/AndroidRuntime(19562):    at dalvik.system.NativeStart.main(Native Method)
04-10 16:59:03.374: E/AndroidRuntime(19562): Caused by: java.lang.NullPointerException
04-10 16:59:03.374: E/AndroidRuntime(19562):    at com.petkovski.mk.TransparentSmsActivity.setCameraDisplayOrientation(TransparentSmsActivity.java:78)
04-10 16:59:03.374: E/AndroidRuntime(19562):    at com.petkovski.mk.TransparentSmsActivity.onCreate(TransparentSmsActivity.java:52)
04-10 16:59:03.374: E/AndroidRuntime(19562):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
04-10 16:59:03.374: E/AndroidRuntime(19562):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1722)
04-10 16:59:03.374: E/AndroidRuntime(19562):    ... 11 more

エラーは、エラーがこのメソッドにあることを示しています

public static void setCameraDisplayOrientation(Activity activity,
             int cameraId, android.hardware.Camera camera) {
         android.hardware.Camera.CameraInfo info =
                 new android.hardware.Camera.CameraInfo();
         android.hardware.Camera.getCameraInfo(cameraId, info);
         int rotation = activity.getWindowManager().getDefaultDisplay()
                 .getRotation();
         int degrees = 0;
         switch (rotation) {
             case Surface.ROTATION_0: degrees = 0; break;
             case Surface.ROTATION_90: degrees = 90; break;
             case Surface.ROTATION_180: degrees = 180; break;
             case Surface.ROTATION_270: degrees = 270; break;
         }

         int result;
         if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
             result = (info.orientation + degrees) % 360;
             result = (360 - result) % 360;  // compensate the mirror
         } else {  // back-facing
             result = (info.orientation - degrees + 360) % 360;
         }
         camera.setDisplayOrientation(result);  //here is the error
     }

このメソッドを次のように呼び出します。

setCameraDisplayOrientation(this,cameraInfo.CAMERA_FACING_BACK, camera);

何が問題なのか誰にも教えてもらえますか?

4

0 に答える 0