所以我正在创建和使用相机 API 的应用程序。该应用程序即将完成,它只需要添加更多功能。但是,当我尝试在模拟器或手机上从 eclipse 启动应用程序时,它会产生运行时错误,提示无法恢复活动:无法连接到相机服务。我尝试了多个模拟器,是的,相机选项已打开。我很困惑为什么它在导出为 apk 并安装在我的手机上时运行完美,但当我尝试在 eclipse 中或模拟器形式调试它时却不起作用。有任何想法吗?因为我现在不可能错误跟踪。我查看了大量与无法连接到相机服务相关的帖子,但没有任何运气将其应用于我的情况。
旁注:相机过去也可以正常工作,几天前可以正常运行这个应用程序,没有任何问题。我的想法是它与日食有关。由于该应用程序在从 apk 运行时可以在我的手机上完美运行
更新:我卸载了eclipse并重新安装了它,同样的错误仍然发生。怎么了?这段代码在我在 eclipse 中运行时不起作用 ahhg
我的日志猫:
05-27 22:20:55.197: E/AndroidRuntime(419): FATAL EXCEPTION: main
05-27 22:20:55.197: E/AndroidRuntime(419): java.lang.RuntimeException: Unable to resume activity {com.fuchs.frontcam/com.fuchs.frontcam.MainActivity}: java.lang.RuntimeException: Fail to connect to camera service
05-27 22:20:55.197: E/AndroidRuntime(419): at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2120)
05-27 22:20:55.197: E/AndroidRuntime(419): at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2135)
05-27 22:20:55.197: E/AndroidRuntime(419): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1668)
05-27 22:20:55.197: E/AndroidRuntime(419): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
05-27 22:20:55.197: E/AndroidRuntime(419): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
05-27 22:20:55.197: E/AndroidRuntime(419): at android.os.Handler.dispatchMessage(Handler.java:99)
05-27 22:20:55.197: E/AndroidRuntime(419): at android.os.Looper.loop(Looper.java:123)
05-27 22:20:55.197: E/AndroidRuntime(419): at android.app.ActivityThread.main(ActivityThread.java:3683)
05-27 22:20:55.197: E/AndroidRuntime(419): at java.lang.reflect.Method.invokeNative(Native Method)
05-27 22:20:55.197: E/AndroidRuntime(419): at java.lang.reflect.Method.invoke(Method.java:507)
05-27 22:20:55.197: E/AndroidRuntime(419): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
05-27 22:20:55.197: E/AndroidRuntime(419): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
05-27 22:20:55.197: E/AndroidRuntime(419): at dalvik.system.NativeStart.main(Native Method)
05-27 22:20:55.197: E/AndroidRuntime(419): Caused by: java.lang.RuntimeException: Fail to connect to camera service
05-27 22:20:55.197: E/AndroidRuntime(419): at android.hardware.Camera.native_setup(Native Method)
05-27 22:20:55.197: E/AndroidRuntime(419): at android.hardware.Camera.<init>(Camera.java:258)
05-27 22:20:55.197: E/AndroidRuntime(419): at android.hardware.Camera.open(Camera.java:220)
05-27 22:20:55.197: E/AndroidRuntime(419): at com.fuchs.frontcam.MainActivity.initCamera(MainActivity.java:56)
05-27 22:20:55.197: E/AndroidRuntime(419): at com.fuchs.frontcam.MainActivity.onResume(MainActivity.java:49)
05-27 22:20:55.197: E/AndroidRuntime(419): at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1150)
05-27 22:20:55.197: E/AndroidRuntime(419): at android.app.Activity.performResume(Activity.java:3832)
05-27 22:20:55.197: E/AndroidRuntime(419): at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2110)
05-27 22:20:55.197: E/AndroidRuntime(419): ... 12 more