java.lang.RuntimeException: Fail to connect to camera service
at android.hardware.Camera.native_setup(Native Method)
at android.hardware.Camera.(Camera.java:362)
at android.hardware.Camera.open(Camera.java:320)
at com.qingmei2.library.zxing.OpenCameraInterface.open(OpenCameraInterface.java)
at com.qingmei2.library.zxing.CameraManager.openDriver(CameraManager.java)
at com.qingmei2.library.view.QRCodeScannerView.surfaceCreated(QRCodeScannerView.java)
at android.view.SurfaceView.updateWindow(SurfaceView.java:593)
at android.view.SurfaceView.access$000(SurfaceView.java:93)
at android.view.SurfaceView$4.setFormat(SurfaceView.java:777)
at com.qingmei2.library.view.QRCodeScannerView.surfaceCreated(QRCodeScannerView.java)
at android.view.SurfaceView.updateWindow(SurfaceView.java:593)
at android.view.SurfaceView.access$000(SurfaceView.java:93)
at android.view.SurfaceView$3.onPreDraw(SurfaceView.java:184)
at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:847)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1951)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1053)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5959)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:780)
at android.view.Choreographer.doCallbacks(Choreographer.java:593)
at android.view.Choreographer.doFrame(Choreographer.java:562)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:766)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5356)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:864)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:680)
at dalvik.system.NativeStart.main(Native Method)
java.lang.RuntimeException: Fail to connect to camera service at android.hardware.Camera.native_setup(Native Method) at android.hardware.Camera.(Camera.java:362)
at android.hardware.Camera.open(Camera.java:320)
at com.qingmei2.library.zxing.OpenCameraInterface.open(OpenCameraInterface.java)
at com.qingmei2.library.zxing.CameraManager.openDriver(CameraManager.java)
at com.qingmei2.library.view.QRCodeScannerView.surfaceCreated(QRCodeScannerView.java)
at android.view.SurfaceView.updateWindow(SurfaceView.java:593)
at android.view.SurfaceView.access$000(SurfaceView.java:93)
at android.view.SurfaceView$4.setFormat(SurfaceView.java:777)
at com.qingmei2.library.view.QRCodeScannerView.surfaceCreated(QRCodeScannerView.java)
at android.view.SurfaceView.updateWindow(SurfaceView.java:593)
at android.view.SurfaceView.access$000(SurfaceView.java:93)
at android.view.SurfaceView$3.onPreDraw(SurfaceView.java:184)
at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:847)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1951)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1053)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5959)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:780)
at android.view.Choreographer.doCallbacks(Choreographer.java:593)
at android.view.Choreographer.doFrame(Choreographer.java:562)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:766)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5356)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:864)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:680)
at dalvik.system.NativeStart.main(Native Method)
建议在open前做一下camera的释放,如下: try{ camera.stopPreview(); camera.release(); camera = null; }catch (Exception e){ return; }