为什么我无法打开相机?
我尝试运行 this ,但它会强制关闭,如下所示
06-29 10:14:14.154: ERROR/AndroidRuntime(4392): java.lang.RuntimeException: Fail to connect to camera service
06-29 10:14:14.154: ERROR/AndroidRuntime(4392): at android.hardware.Camera.native_setup(Native Method)
06-29 10:14:14.154: ERROR/AndroidRuntime(4392): at android.hardware.Camera.<init>(Camera.java:294)
06-29 10:14:14.154: ERROR/AndroidRuntime(4392): at android.hardware.Camera.open(Camera.java:271)
06-29 10:14:14.154: ERROR/AndroidRuntime(4392): at com.example.Preview.surfaceCreated(Preview.java:37)
06-29 10:14:14.154: ERROR/AndroidRuntime(4392): at android.view.SurfaceView.updateWindow(SurfaceView.java:543)
06-29 10:14:14.154: ERROR/AndroidRuntime(4392): at android.view.SurfaceView.dispatchDraw(SurfaceView.java:348)
06-29 10:14:14.154: ERROR/AndroidRuntime(4392): at android.view.ViewGroup.drawChild(ViewGroup.java:1644)
06-29 10:14:14.154: ERROR/AndroidRuntime(4392): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
06-29 10:14:14.154: ERROR/AndroidRuntime(4392): at android.view.ViewGroup.drawChild(ViewGroup.java:1644)
06-29 10:14:14.154: ERROR/AndroidRuntime(4392): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
06-29 10:14:14.154: ERROR/AndroidRuntime(4392): at android.view.ViewGroup.drawChild(ViewGroup.java:1644)
06-29 10:14:14.154: ERROR/AndroidRuntime(4392): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
06-29 10:14:14.154: ERROR/AndroidRuntime(4392): at android.view.View.draw(View.java:6936)
06-29 10:14:14.154: ERROR/AndroidRuntime(4392): at android.widget.FrameLayout.draw(FrameLayout.java:357)
06-29 10:14:14.154: ERROR/AndroidRuntime(4392): at android.view.ViewGroup.drawChild(ViewGroup.java:1646)
06-29 10:14:14.154: ERROR/AndroidRuntime(4392): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
06-29 10:14:14.154: ERROR/AndroidRuntime(4392): at android.view.ViewGroup.drawChild(ViewGroup.java:1644)
06-29 10:14:14.154: ERROR/AndroidRuntime(4392): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
06-29 10:14:14.154: ERROR/AndroidRuntime(4392): at android.view.View.draw(View.java:6936)
06-29 10:14:14.154: ERROR/AndroidRuntime(4392): at android.widget.FrameLayout.draw(FrameLayout.java:357)
06-29 10:14:14.154: ERROR/AndroidRuntime(4392): at com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:1904)
06-29 10:14:14.154: ERROR/AndroidRuntime(4392): at android.view.ViewRoot.draw(ViewRoot.java:1527)
06-29 10:14:14.154: ERROR/AndroidRuntime(4392): at android.view.ViewRoot.performTraversals(ViewRoot.java:1263)
06-29 10:14:14.154: ERROR/AndroidRuntime(4392): at android.view.ViewRoot.handleMessage(ViewRoot.java:1865)
06-29 10:14:14.154: ERROR/AndroidRuntime(4392): at android.os.Handler.dispatchMessage(Handler.java:99)
06-29 10:14:14.154: ERROR/AndroidRuntime(4392): at android.os.Looper.loop(Looper.java:123)
06-29 10:14:14.154: ERROR/AndroidRuntime(4392): at android.app.ActivityThread.main(ActivityThread.java:3687)
06-29 10:14:14.154: ERROR/AndroidRuntime(4392): at java.lang.reflect.Method.invokeNative(Native Method)
06-29 10:14:14.154: ERROR/AndroidRuntime(4392): at java.lang.reflect.Method.invoke(Method.java:507)
06-29 10:14:14.154: ERROR/AndroidRuntime(4392): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842)
06-29 10:14:14.154: ERROR/AndroidRuntime(4392): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
06-29 10:14:14.154: ERROR/AndroidRuntime(4392): at dalvik.system.NativeStart.main(Native Method)
I try to run this , but it force close happen like this
06-29 10:14:14.154: ERROR/AndroidRuntime(4392): java.lang.RuntimeException: Fail to connect to camera service
06-29 10:14:14.154: ERROR/AndroidRuntime(4392): at android.hardware.Camera.native_setup(Native Method)
06-29 10:14:14.154: ERROR/AndroidRuntime(4392): at android.hardware.Camera.<init>(Camera.java:294)
06-29 10:14:14.154: ERROR/AndroidRuntime(4392): at android.hardware.Camera.open(Camera.java:271)
06-29 10:14:14.154: ERROR/AndroidRuntime(4392): at com.example.Preview.surfaceCreated(Preview.java:37)
06-29 10:14:14.154: ERROR/AndroidRuntime(4392): at android.view.SurfaceView.updateWindow(SurfaceView.java:543)
06-29 10:14:14.154: ERROR/AndroidRuntime(4392): at android.view.SurfaceView.dispatchDraw(SurfaceView.java:348)
06-29 10:14:14.154: ERROR/AndroidRuntime(4392): at android.view.ViewGroup.drawChild(ViewGroup.java:1644)
06-29 10:14:14.154: ERROR/AndroidRuntime(4392): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
06-29 10:14:14.154: ERROR/AndroidRuntime(4392): at android.view.ViewGroup.drawChild(ViewGroup.java:1644)
06-29 10:14:14.154: ERROR/AndroidRuntime(4392): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
06-29 10:14:14.154: ERROR/AndroidRuntime(4392): at android.view.ViewGroup.drawChild(ViewGroup.java:1644)
06-29 10:14:14.154: ERROR/AndroidRuntime(4392): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
06-29 10:14:14.154: ERROR/AndroidRuntime(4392): at android.view.View.draw(View.java:6936)
06-29 10:14:14.154: ERROR/AndroidRuntime(4392): at android.widget.FrameLayout.draw(FrameLayout.java:357)
06-29 10:14:14.154: ERROR/AndroidRuntime(4392): at android.view.ViewGroup.drawChild(ViewGroup.java:1646)
06-29 10:14:14.154: ERROR/AndroidRuntime(4392): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
06-29 10:14:14.154: ERROR/AndroidRuntime(4392): at android.view.ViewGroup.drawChild(ViewGroup.java:1644)
06-29 10:14:14.154: ERROR/AndroidRuntime(4392): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
06-29 10:14:14.154: ERROR/AndroidRuntime(4392): at android.view.View.draw(View.java:6936)
06-29 10:14:14.154: ERROR/AndroidRuntime(4392): at android.widget.FrameLayout.draw(FrameLayout.java:357)
06-29 10:14:14.154: ERROR/AndroidRuntime(4392): at com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:1904)
06-29 10:14:14.154: ERROR/AndroidRuntime(4392): at android.view.ViewRoot.draw(ViewRoot.java:1527)
06-29 10:14:14.154: ERROR/AndroidRuntime(4392): at android.view.ViewRoot.performTraversals(ViewRoot.java:1263)
06-29 10:14:14.154: ERROR/AndroidRuntime(4392): at android.view.ViewRoot.handleMessage(ViewRoot.java:1865)
06-29 10:14:14.154: ERROR/AndroidRuntime(4392): at android.os.Handler.dispatchMessage(Handler.java:99)
06-29 10:14:14.154: ERROR/AndroidRuntime(4392): at android.os.Looper.loop(Looper.java:123)
06-29 10:14:14.154: ERROR/AndroidRuntime(4392): at android.app.ActivityThread.main(ActivityThread.java:3687)
06-29 10:14:14.154: ERROR/AndroidRuntime(4392): at java.lang.reflect.Method.invokeNative(Native Method)
06-29 10:14:14.154: ERROR/AndroidRuntime(4392): at java.lang.reflect.Method.invoke(Method.java:507)
06-29 10:14:14.154: ERROR/AndroidRuntime(4392): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842)
06-29 10:14:14.154: ERROR/AndroidRuntime(4392): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
06-29 10:14:14.154: ERROR/AndroidRuntime(4392): at dalvik.system.NativeStart.main(Native Method)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
听起来您的设备没有摄像头(模拟器!),或者您没有在清单中定义适当的权限。
Sounds like your device does not have a camera (emulator!) or that you dont have the appropriate permissions defined in your manifest.
我认为问题出在您的设备上,因为教程要求您添加权限。编辑您的 AVD 并在硬件中添加相机支持
I think the problem is in your device, because the tutorial has ask you to add the permission. Edit your AVD and add camera support in hardware