我已经开始运行我的应用程序,遇到了这个问题
RuntimeException: Unable to resume activity
但是我发现了问题。这是在我的方法protected void onPause()
中。如果我删除了camera = null
行,它不会改变。
我试图修复,但我做不到
@Override
protected void onResume() {
super.onResume();
camera = Camera.open();
}
@Override
protected void onPause() {
super.onPause();
if (camera != null) {
camera.setPreviewCallback(null);
camera.stopPreview();
camera.release();
camera = null;
}
}
日志是:
java.lang.RuntimeException: Unable to resume activity {com.example.scanera/com.example.scanera.MainActivity}: java.lang.RuntimeException: Fail to connect to camera service
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3502)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3542)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2790)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1523)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:163)
at android.app.ActivityThread.main(ActivityThread.java:6238)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:904)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:794)
Caused by: java.lang.RuntimeException: Fail to connect to camera service
at android.hardware.Camera.<init>(Camera.java:579)
at android.hardware.Camera.open(Camera.java:419)
at com.example.scanera.MainActivity.onResume(MainActivity.java:170)
at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1270)
at android.app.Activity.performResume(Activity.java:6981)
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3479)