Click here to Skip to main content
15,888,283 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
Hi,
I have developed a flashlight app that runs the led light from the camera. But i have 2 errors that i am not sure how to fix.

Here they are:

*Runtime error - is this because the device doesnt have led light or camera?

---------------------------

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.moschdev.hd.flashlight/com.moschdev.hd.flashlight.FlashLightActivity}: java.lang.RuntimeException: Fail to connect to camera service
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1976)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2001)
at android.app.ActivityThread.access$600(ActivityThread.java:130)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1163)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4444)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:787)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:554)
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.<init>(Camera.java:327)
at android.hardware.Camera.open(Camera.java:302)
at com.moschdev.hd.flashlight.FlashLightActivity.onCreate(FlashLightActivity.java:46)
at android.app.Activity.performCreate(Activity.java:4494)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1940)


*Runtime error - This error really confused me!
------------------------------


java.lang.RuntimeException: setParameters failed
at android.hardware.Camera.native_setParameters(Native Method)
at android.hardware.Camera.setParameters(Camera.java:1010)
at com.moschdev.hd.flashlight.FlashLightActivity$1.onClick(FlashLightActivity.java:76)
at android.view.View.performClick(View.java:2485)
at android.widget.CompoundButton.performClick(CompoundButton.java:99)
at android.view.View$PerformClick.run(View.java:9080)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3717)
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:864)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:622)
at dalvik.system.NativeStart.main(Native Method)

Any help would be well appreciated!
Posted

1 solution

Hi there,

This seems pretty obvious but hopefully it helps:

Your first exception says "Failed to connect to camera service.".
Therefore, when you attempt to set the Camera parameters, you get your second exception since you have not connected to the Camera service so it cannot possibly set the Camera parameters.

If the device doesn't have a camera then that is precisely why your app doesn't work. How could it possibly connect to something that doesn't exist?

If the device does have a camera, here are a few possibilities:
1) Have you remembered to add the required camera permissions to your App Manifest - if you haven't then that is why it would fail to connect to the Camera Service.
2) Make sure you haven't somehow disabled the Camera Service and that the normal camera app works - if the default camera app doesn't work then it is a phone issue not your code.
3) Make sure you read the Android documentation on how to use the Camera Service - make sure you have done all the necessary set-up, parameters, permissions etc. for it to work.

Hope this helps,
Ed
 
Share this answer
 
Comments
Mosch Dev. 18-Nov-12 0:51am    
Hi,
I have done everything you have ask. Is it possible that i could just check if the device has a camera? Then if not display a message telling so, but without the app force closing?
Ed Nutting 18-Nov-12 6:42am    
Hmm...a quick search in Google revealed that as of Android 1.6, all android installations must report to have a camera regardless of whether they do or not. Therefore, your app should never have a problem. I cannot see why you would get error messages like these if you have done everything I suggested... I suggest you search Google to try and find a good example of how to use the Camera Service - you may spot something you are missing.

Sorry that I cannot help further,
Ed

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900