为什么我无法打开相机?

发布于 2024-11-17 10:04:32 字数 3758 浏览 1 评论 0原文

我尝试运行 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

三岁铭 2024-11-24 10:04:32

听起来您的设备没有摄像头(模拟器!),或者您没有在清单中定义适当的权限。

android.permission.CAMERA

Sounds like your device does not have a camera (emulator!) or that you dont have the appropriate permissions defined in your manifest.

android.permission.CAMERA
绅刃 2024-11-24 10:04:32

我认为问题出在您的设备上,因为教程要求您添加权限。编辑您的 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文