Fail to connect to camera service Android java RuntimeException


FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo {com.code2care.tools
.app/com.code2care.tools.app.MainActivity}: 
java.lang.RuntimeException: Fail to connect to camera service
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:2836)
at android.app.ActivityThread.access$1600(ActivityThread.java:117)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:939)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3687)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:878)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:636)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.RuntimeException: Fail to connect to camera service
at android.hardware.Camera.native_setup(Native Method)
at android.hardware.Camera.(Camera.java:291)
at android.hardware.Camera.open(Camera.java:266)
at com.code2care.tools.app.MainActivity.onCreate(MainActivity.java:59)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
... 12 more

You have used the Camara hardware java code in your Android application everything seems fine with no errors in eclipse project files, but it fails on runtime ?

Reason: Any hardware you use like Bluetooth, Camara, Wifi, or other sensors you need to get the Permissions from the user that your app wants them. To do so you need to add this code in AndroidManifest.xml file.

For Camara App add the following lines :

<uses-permission android:name = "android.permission.CAMERA"/>

Try running the App now you will not the Camara RuntimeException exception.