在我的活動中,我有3個Tabost,第一個是畫廊第二個是相機,第三個是視頻,當我點擊相機它的開放和用戶可以很容易地拍照,其工作正常和點擊另一個tabhost其他事情發生,但當我再次點擊相機,然後應用程序崩潰,它顯示錯誤「OnResume相機錯誤..不能連接到相機服務」OnResume相機錯誤..不能連接到相機服務
以下是我的簡歷代碼... 。
protected void onResume() {
super.onResume();
// TODO Auto-generated method stub
if(camera==null){
camera = Camera.open();
camera.startPreview();
camera.setErrorCallback(new ErrorCallback() {
public void onError(int error, Camera mcamera) {
camera.release();
camera = Camera.open();
Log.d("Camera died", "error camera");
}
});
}
if (camera != null) {
if (Build.VERSION.SDK_INT >= 14)
setCameraDisplayOrientation(context,
CameraInfo.CAMERA_FACING_BACK, camera);
preview.setCamera(camera);
}
}
主要在這裏示出了誤差在該線陣相機= Camera.open();
我試圖用相機釋放的onPause,但沒有工作..請提出好的建議
的logcat:
09-18 15:35:29.595: E/AndroidRuntime(9598): FATAL EXCEPTION: main
09-18 15:35:29.595: E/AndroidRuntime(9598): Process: com.example.rooshan, PID: 9598
09-18 15:35:29.595: E/AndroidRuntime(9598): java.lang.RuntimeException: Unable to resume activity {com.example.rooshan/com.rooshan.main.Photo_Activity}: java.lang.RuntimeException: Fail to connect to camera service
09-18 15:35:29.595: E/AndroidRuntime(9598): at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2955)
09-18 15:35:29.595: E/AndroidRuntime(9598): at android.app.LocalActivityManager.moveToState(LocalActivityManager.java:146)
09-18 15:35:29.595: E/AndroidRuntime(9598): at android.app.LocalActivityManager.startActivity(LocalActivityManager.java:347)
09-18 15:35:29.595: E/AndroidRuntime(9598): at android.widget.TabHost$IntentContentStrategy.getContentView(TabHost.java:749)
09-18 15:35:29.595: E/AndroidRuntime(9598): at android.widget.TabHost.setCurrentTab(TabHost.java:413)
09-18 15:35:29.595: E/AndroidRuntime(9598): at android.widget.TabHost$2.onTabSelectionChanged(TabHost.java:154)
09-18 15:35:29.595: E/AndroidRuntime(9598): at android.widget.TabWidget$TabClickListener.onClick(TabWidget.java:546)
09-18 15:35:29.595: E/AndroidRuntime(9598): at android.view.View.performClick(View.java:4478)
09-18 15:35:29.595: E/AndroidRuntime(9598): at android.view.View$PerformClick.run(View.java:18698)
09-18 15:35:29.595: E/AndroidRuntime(9598): at android.os.Handler.handleCallback(Handler.java:733)
09-18 15:35:29.595: E/AndroidRuntime(9598): at android.os.Handler.dispatchMessage(Handler.java:95)
09-18 15:35:29.595: E/AndroidRuntime(9598): at android.os.Looper.loop(Looper.java:149)
09-18 15:35:29.595: E/AndroidRuntime(9598): at android.app.ActivityThread.main(ActivityThread.java:5257)
09-18 15:35:29.595: E/AndroidRuntime(9598): at java.lang.reflect.Method.invokeNative(Native Method)
09-18 15:35:29.595: E/AndroidRuntime(9598): at java.lang.reflect.Method.invoke(Method.java:515)
09-18 15:35:29.595: E/AndroidRuntime(9598): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
09-18 15:35:29.595: E/AndroidRuntime(9598): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:609)
09-18 15:35:29.595: E/AndroidRuntime(9598): at dalvik.system.NativeStart.main(Native Method)
09-18 15:35:29.595: E/AndroidRuntime(9598): Caused by: java.lang.RuntimeException: Fail to connect to camera service
09-18 15:35:29.595: E/AndroidRuntime(9598): at android.hardware.Camera.native_setup(Native Method)
09-18 15:35:29.595: E/AndroidRuntime(9598): at android.hardware.Camera.<init>(Camera.java:407)
09-18 15:35:29.595: E/AndroidRuntime(9598): at android.hardware.Camera.open(Camera.java:345)
09-18 15:35:29.595: E/AndroidRuntime(9598): at com.rooshan.main.Photo_Activity.onResume(Photo_Activity.java:93)
09-18 15:35:29.595: E/AndroidRuntime(9598): at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1192)
09-18 15:35:29.595: E/AndroidRuntime(9598): at android.app.Activity.performResume(Activity.java:5490)
09-18 15:35:29.595: E/AndroidRuntime(9598): at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2945)
09-18 15:35:29.595: E/AndroidRuntime(9598): ... 17 more
附加的logcat的錯誤 – Bhargav
請我已經更新了我的問題與logcat –
您是否在清單中爲Camera添加權限? – shiladitya