0
不工作,我有一個應用程序,我打開攝像頭在onResume()
方法:安卓:Camera.open()中的onResume()方法
@Override
public void onResume() {
super.onResume();
openCamera();
....
}
public void openCamera() {
try {
camera = Camera.open();
Log.d(CAMERA, "Camre opened");
} catch (Exception exception) {
Log.e(CAMERA, "Cannot open camera", exception);
}
}
openCamera()如果我不叫方法,工作正常它onResume()
的方法,但onResume()
方法中它使我有以下異常:
08-15 14:50:33.999: E/camera(1753): Cannot open camera
08-15 14:50:33.999: E/camera(1753): java.lang.RuntimeException: Fail to connect to camera service
08-15 14:50:33.999: E/camera(1753): at android.hardware.Camera.native_setup(Native Method)
08-15 14:50:33.999: E/camera(1753): at android.hardware.Camera.<init>(Camera.java:302)
08-15 14:50:33.999: E/camera(1753): at android.hardware.Camera.open(Camera.java:279)
08-15 14:50:33.999: E/camera(1753): at buet.threebyzero.autoSecuritySystem.Capture.openCamera(Capture.java:46)
08-15 14:50:33.999: E/camera(1753): at buet.threebyzero.autoSecuritySystem.Capture.onResume(Capture.java:55)
08-15 14:50:33.999: E/camera(1753): at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1154)
08-15 14:50:33.999: E/camera(1753): at android.app.Activity.performResume(Activity.java:4539)
08-15 14:50:33.999: E/camera(1753): at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2434)
08-15 14:50:33.999: E/camera(1753): at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2472)
08-15 14:50:33.999: E/camera(1753): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1986)
08-15 14:50:33.999: E/camera(1753): at android.app.ActivityThread.access$600(ActivityThread.java:123)
08-15 14:50:33.999: E/camera(1753): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
08-15 14:50:33.999: E/camera(1753): at android.os.Handler.dispatchMessage(Handler.java:99)
08-15 14:50:33.999: E/camera(1753): at android.os.Looper.loop(Looper.java:137)
08-15 14:50:33.999: E/camera(1753): at android.app.ActivityThread.main(ActivityThread.java:4424)
08-15 14:50:33.999: E/camera(1753): at java.lang.reflect.Method.invokeNative(Native Method)
08-15 14:50:33.999: E/camera(1753): at java.lang.reflect.Method.invoke(Method.java:511)
08-15 14:50:33.999: E/camera(1753): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
08-15 14:50:33.999: E/camera(1753): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
08-15 14:50:33.999: E/camera(1753): at dalvik.system.NativeStart.main(Native Method)
編輯:問題重啓仿真器和壓倒一切的後,部分解決了210方法:
@Override
protected void onPause() {
super.onPause();
if(camera != null)
camera.release();
}
每次調用'onResume()',即使在'onCreate()'之後,我都會得到這個異常。 – 2012-08-15 09:10:53