我在我的代码中使用虚拟表面.它在运行4.2.1的Canvas HD中运行良好但是当我的nexus 5 / S 3上部署了相同的应用程序时,它在camera.takepicture上提供RunTimeException
这是我的代码
{
camera = Camera.open(cameraId);
if (camera != null)
{
SurfaceView dummy = new SurfaceView(context);
try {
camera.setPreviewDisplay(dummy.getHolder());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
camera.startPreview();
camera.takePicture(null,null,new PhotoHandler(context));
}
logcat的:
07-17 22:46:49.281: E/AndroidRuntime(481): FATAL EXCEPTION: main
07-17 22:46:49.281: E/AndroidRuntime(481): Process: com.example.ex,PID: 481
07-17 22:46:49.281: E/AndroidRuntime(481): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.ex/com.example.ex.MainActivity}: java.lang.RuntimeException: takePicture Failed
07-17 22:46:49.281: E/AndroidRuntime(481): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2184)
07-17 22:46:49.281: E/AndroidRuntime(481): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
07-17 22:46:49.281: E/AndroidRuntime(481): at android.app.ActivityThread.access$800(ActivityThread.java:135)
07-17 22:46:49.281: E/AndroidRuntime(481): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
07-17 22:46:49.281: E/AndroidRuntime(481): at android.os.Handler.dispatchMessage(Handler.java:102)
07-17 22:46:49.281: E/AndroidRuntime(481): at android.os.Looper.loop(Looper.java:136)
07-17 22:46:49.281: E/AndroidRuntime(481): at android.app.ActivityThread.main(ActivityThread.java:5001)
07-17 22:46:49.281: E/AndroidRuntime(481): at java.lang.reflect.Method.invokeNative(Native Method)
07-17 22:46:49.281: E/AndroidRuntime(481): at java.lang.reflect.Method.invoke(Method.java:515)
07-17 22:46:49.281: E/AndroidRuntime(481): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
07-17 22:46:49.281: E/AndroidRuntime(481): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
07-17 22:46:49.281: E/AndroidRuntime(481): at dalvik.system.NativeStart.main(Native Method)
07-17 22:46:49.281: E/AndroidRuntime(481): Caused by: java.lang.RuntimeException: takePicture Failed
07-17 22:46:49.281: E/AndroidRuntime(481): at android.hardware.Camera.native_takePicture(Native Method)
07-17 22:46:49.281: E/AndroidRuntime(481): at android.hardware.Camera.takePicture(Camera.java:1245)
07-17 22:46:49.281: E/AndroidRuntime(481): at android.hardware.Camera.takePicture(Camera.java:1190)
07-17 22:46:49.281: E/AndroidRuntime(481): at com.example.ex.MainActivity.capturephoto(MainActivity.java:63)
07-17 22:46:49.281: E/AndroidRuntime(481): at com.example.ex.MainActivity.onCreate(MainActivity.java:26)
07-17 22:46:49.281: E/AndroidRuntime(481): at android.app.Activity.performCreate(Activity.java:5231)
07-17 22:46:49.281: E/AndroidRuntime(481): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
07-17 22:46:49.281: E/AndroidRuntime(481): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148)
最佳答案