0

必要なすべての権限を使用しました。

<uses-permission android:name="android.permission.CAMERA" /> 
<uses-feature android:name="android.hardware.camera" android:required="false" />
<uses-feature android:name="android.hardware.camera.front" android:required="false" />

そして、私が使用したコードは次のとおりです。

private Camera openFrontFacingCameraGingerbread()
{ int cameraCount = 0;
    Camera cam = null;
    Camera.CameraInfo cameraInfo = new Camera.CameraInfo();
    cameraCount = Camera.getNumberOfCameras();
    for (int camIdx = 0; camIdx < cameraCount; camIdx++)
    { Camera.getCameraInfo(camIdx, cameraInfo);
        if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_FRONT)
        { try { cam = Camera.open(camIdx);
        } catch (RuntimeException e)
        { Log.e(TAG, "Camera failed to open: " + e.getLocalizedMessage());
        }
        }
    } return cam;
}

しかし、エラーが発生しています。Logcat エラー:

Cannot connect camera service

以下に提供されているソリューションの Logcat、

FATAL EXCEPTION: main
04-07 16:25:40.935 4090-4090/? E/AndroidRuntime: Process: pop.lock.com.frocam, PID: 4090
04-07 16:25:40.935 4090-4090/? E/AndroidRuntime: java.lang.IllegalStateException: Could not execute method of the activity
04-07 16:25:40.935 4090-4090/? E/AndroidRuntime:     at android.view.View$1.onClick(View.java:3848)
04-07 16:25:40.935 4090-4090/? E/AndroidRuntime:     at android.view.View.performClick(View.java:4463)
04-07 16:25:40.935 4090-4090/? E/AndroidRuntime:     at android.view.View$PerformClick.run(View.java:18770)
04-07 16:25:40.935 4090-4090/? E/AndroidRuntime:     at android.os.Handler.handleCallback(Handler.java:808)
04-07 16:25:40.935 4090-4090/? E/AndroidRuntime:     at android.os.Handler.dispatchMessage(Handler.java:103)
04-07 16:25:40.935 4090-4090/? E/AndroidRuntime:     at android.os.Looper.loop(Looper.java:193)
04-07 16:25:40.935 4090-4090/? E/AndroidRuntime:     at android.app.ActivityThread.main(ActivityThread.java:5333)
04-07 16:25:40.935 4090-4090/? E/AndroidRuntime:     at java.lang.reflect.Method.invokeNative(Native Method)
04-07 16:25:40.935 4090-4090/? E/AndroidRuntime:     at java.lang.reflect.Method.invoke(Method.java:515)
04-07 16:25:40.935 4090-4090/? E/AndroidRuntime:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:828)
04-07 16:25:40.935 4090-4090/? E/AndroidRuntime:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:644)
04-07 16:25:40.935 4090-4090/? E/AndroidRuntime:     at dalvik.system.NativeStart.main(Native Method)
04-07 16:25:40.935 4090-4090/? E/AndroidRuntime:  Caused by: java.lang.reflect.InvocationTargetException
04-07 16:25:40.935 4090-4090/? E/AndroidRuntime:     at java.lang.reflect.Method.invokeNative(Native Method)
04-07 16:25:40.935 4090-4090/? E/AndroidRuntime:     at java.lang.reflect.Method.invoke(Method.java:515)
04-07 16:25:40.935 4090-4090/? E/AndroidRuntime:     at android.view.View$1.onClick(View.java:3843)
04-07 16:25:40.935 4090-4090/? E/AndroidRuntime:     at android.view.View.performClick(View.java:4463) 
04-07 16:25:40.935 4090-4090/? E/AndroidRuntime:     at android.view.View$PerformClick.run(View.java:18770) 
04-07 16:25:40.935 4090-4090/? E/AndroidRuntime:     at android.os.Handler.handleCallback(Handler.java:808) 
04-07 16:25:40.935 4090-4090/? E/AndroidRuntime:     at android.os.Handler.dispatchMessage(Handler.java:103) 
04-07 16:25:40.935 4090-4090/? E/AndroidRuntime:     at android.os.Looper.loop(Looper.java:193) 
04-07 16:25:40.935 4090-4090/? E/AndroidRuntime:     at android.app.ActivityThread.main(ActivityThread.java:5333) 
04-07 16:25:40.935 4090-4090/? E/AndroidRuntime:     at java.lang.reflect.Method.invokeNative(Native Method) 
04-07 16:25:40.935 4090-4090/? E/AndroidRuntime:     at java.lang.reflect.Method.invoke(Method.java:515) 
04-07 16:25:40.935 4090-4090/? E/AndroidRuntime:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:828) 
04-07 16:25:40.935 4090-4090/? E/AndroidRuntime:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:644) 
04-07 16:25:40.935 4090-4090/? E/AndroidRuntime:     at dalvik.system.NativeStart.main(Native Method) 
04-07 16:25:40.935 4090-4090/? E/AndroidRuntime:  Caused by: java.lang.NullPointerException
04-07 16:25:40.935 4090-4090/? E/AndroidRuntime:     at pop.lock.com.frocam.FrontCamActivity.onClick(FrontCamActivity.java:41)
04-07 16:25:40.935 4090-4090/? E/AndroidRuntime:     at java.lang.reflect.Method.invokeNative(Native Method) 
04-07 16:25:40.935 4090-4090/? E/AndroidRuntime:     at java.lang.reflect.Method.invoke(Method.java:515) 
04-07 16:25:40.935 4090-4090/? E/AndroidRuntime:     at android.view.View$1.onClick(View.java:3843) 
04-07 16:25:40.935 4090-4090/? E/AndroidRuntime:     at android.view.View.performClick(View.java:4463) 
04-07 16:25:40.935 4090-4090/? E/AndroidRuntime:     at android.view.View$PerformClick.run(View.java:18770) 
04-07 16:25:40.935 4090-4090/? E/AndroidRuntime:     at android.os.Handler.handleCallback(Handler.java:808) 
04-07 16:25:40.935 4090-4090/? E/AndroidRuntime:     at android.os.Handler.dispatchMessage(Handler.java:103) 
04-07 16:25:40.935 4090-4090/? E/AndroidRuntime:     at android.os.Looper.loop(Looper.java:193) 

私は compilesdkversion 23 を使用しており、4.4.2 kitkat HTC 816g モバイルを使用してアプリケーションを実行しています。カメラ サービスに関連するコードは実行されていません。

4

1 に答える 1