[Solved] Fail to connect to camera service

Common bugs/problems with the Android SDK the Emulator and the ADT-Plugin.

[Solved] Fail to connect to camera service

Postby macuserlambda » Mon Mar 28, 2011 10:56 am

hi,

I have an issue using camera in my app. Half the time, my app crashes at launching with following error :
Code: Select all
03-28 10:27:38.517: ERROR/AndroidRuntime(1415): FATAL EXCEPTION: main
03-28 10:27:38.517: ERROR/AndroidRuntime(1415): java.lang.RuntimeException: Fail to connect to camera service
03-28 10:27:38.517: ERROR/AndroidRuntime(1415):     at android.hardware.Camera.native_setup(Native Method)
03-28 10:27:38.517: ERROR/AndroidRuntime(1415):     at android.hardware.Camera.<init>(Camera.java:118)
03-28 10:27:38.517: ERROR/AndroidRuntime(1415):     at android.hardware.Camera.open(Camera.java:91)
03-28 10:27:38.517: ERROR/AndroidRuntime(1415):     at biz.kasual.smartbordeaux.Preview.surfaceCreated(Preview.java:41)
03-28 10:27:38.517: ERROR/AndroidRuntime(1415):     at android.view.SurfaceView.updateWindow(SurfaceView.java:540)
03-28 10:27:38.517: ERROR/AndroidRuntime(1415):     at android.view.SurfaceView.dispatchDraw(SurfaceView.java:339)
03-28 10:27:38.517: ERROR/AndroidRuntime(1415):     at android.view.ViewGroup.drawChild(ViewGroup.java:1646)
03-28 10:27:38.517: ERROR/AndroidRuntime(1415):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1375)
03-28 10:27:38.517: ERROR/AndroidRuntime(1415):     at android.view.ViewGroup.drawChild(ViewGroup.java:1646)
03-28 10:27:38.517: ERROR/AndroidRuntime(1415):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1375)
03-28 10:27:38.517: ERROR/AndroidRuntime(1415):     at android.view.ViewGroup.drawChild(ViewGroup.java:1646)
03-28 10:27:38.517: ERROR/AndroidRuntime(1415):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1375)
03-28 10:27:38.517: ERROR/AndroidRuntime(1415):     at android.view.ViewGroup.drawChild(ViewGroup.java:1646)
03-28 10:27:38.517: ERROR/AndroidRuntime(1415):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1375)
03-28 10:27:38.517: ERROR/AndroidRuntime(1415):     at android.view.View.draw(View.java:6742)
03-28 10:27:38.517: ERROR/AndroidRuntime(1415):     at android.widget.FrameLayout.draw(FrameLayout.java:352)
03-28 10:27:38.517: ERROR/AndroidRuntime(1415):     at android.view.ViewGroup.drawChild(ViewGroup.java:1648)
03-28 10:27:38.517: ERROR/AndroidRuntime(1415):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1375)
03-28 10:27:38.517: ERROR/AndroidRuntime(1415):     at android.view.ViewGroup.drawChild(ViewGroup.java:1646)
03-28 10:27:38.517: ERROR/AndroidRuntime(1415):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1375)
03-28 10:27:38.517: ERROR/AndroidRuntime(1415):     at android.view.ViewGroup.drawChild(ViewGroup.java:1646)
03-28 10:27:38.517: ERROR/AndroidRuntime(1415):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1375)
03-28 10:27:38.517: ERROR/AndroidRuntime(1415):     at android.view.ViewGroup.drawChild(ViewGroup.java:1646)
03-28 10:27:38.517: ERROR/AndroidRuntime(1415):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1375)
03-28 10:27:38.517: ERROR/AndroidRuntime(1415):     at android.view.View.draw(View.java:6742)
03-28 10:27:38.517: ERROR/AndroidRuntime(1415):     at android.widget.FrameLayout.draw(FrameLayout.java:352)
03-28 10:27:38.517: ERROR/AndroidRuntime(1415):     at android.view.ViewGroup.drawChild(ViewGroup.java:1648)
03-28 10:27:38.517: ERROR/AndroidRuntime(1415):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1375)
03-28 10:27:38.517: ERROR/AndroidRuntime(1415):     at android.view.View.draw(View.java:6742)
03-28 10:27:38.517: ERROR/AndroidRuntime(1415):     at android.widget.FrameLayout.draw(FrameLayout.java:352)
03-28 10:27:38.517: ERROR/AndroidRuntime(1415):     at com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:1872)
03-28 10:27:38.517: ERROR/AndroidRuntime(1415):     at android.view.ViewRoot.draw(ViewRoot.java:1422)
03-28 10:27:38.517: ERROR/AndroidRuntime(1415):     at android.view.ViewRoot.performTraversals(ViewRoot.java:1167)
03-28 10:27:38.517: ERROR/AndroidRuntime(1415):     at android.view.ViewRoot.handleMessage(ViewRoot.java:1744)
03-28 10:27:38.517: ERROR/AndroidRuntime(1415):     at android.os.Handler.dispatchMessage(Handler.java:99)
03-28 10:27:38.517: ERROR/AndroidRuntime(1415):     at android.os.Looper.loop(Looper.java:144)
03-28 10:27:38.517: ERROR/AndroidRuntime(1415):     at android.app.ActivityThread.main(ActivityThread.java:4937)
03-28 10:27:38.517: ERROR/AndroidRuntime(1415):     at java.lang.reflect.Method.invokeNative(Native Method)
03-28 10:27:38.517: ERROR/AndroidRuntime(1415):     at java.lang.reflect.Method.invoke(Method.java:521)
03-28 10:27:38.517: ERROR/AndroidRuntime(1415):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
03-28 10:27:38.517: ERROR/AndroidRuntime(1415):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
03-28 10:27:38.517: ERROR/AndroidRuntime(1415):     at dalvik.system.NativeStart.main(Native Method)


Actually, it works well at first launching but, when I bring the app to foreground, I get this error.

I can't find how to fix it. Any idea ?

Thanks in advance.
Last edited by macuserlambda on Tue Mar 29, 2011 3:04 pm, edited 2 times in total.
macuserlambda
Junior Developer
Junior Developer
 
Posts: 15
Joined: Mon Mar 28, 2011 10:43 am

Top

Re: Fail to connect to camera service

Postby raj_J2ME » Tue Mar 29, 2011 7:24 am

These two thread are talking about more or less the same issue. Please refer the same and check if you can fix the issue with the help of these.

http://androidforums.com/application-de ... -demo.html
http://stackoverflow.com/questions/1745688/fail-to-connect-to-camera-service-on-g1

Check and revert..:)
Thanks with Regards,
Raj - The Kernel
raj_J2ME
Master Developer
Master Developer
 
Posts: 311
Joined: Tue Feb 15, 2011 7:40 am
Location: The Capital of India,

Re: Fail to connect to camera service

Postby macuserlambda » Tue Mar 29, 2011 10:38 am

thanks for your answer.

I saw theses threads before but they don't help me.

My manifest file is OK and my app works the first time I launch it. It crashes only when I quit and come back. It seems like it can't launch camera when I bring the app to foreground.

I call stopPreview() in onStop and onPause. I call startPreview() in onResume.

I have another issue in relation with the previous :
I have a tabbar. The first tab contains my camera preview activity. The second contains a ListView activity and the third contains a WebView activity.
When I show the second tab, onPause of the first activity and so stopPreview() are called as expected. But when, in my second tab, I create an Itent to show a new activity, onStop of first Activity is called !
And when I press back button to come back to the ListView, my app crashes with error "Fail to connect to camera service" again.

I'm new in Android dev so may be I don't understand the whole mechanism.

Someone could help me ?

Thanks
macuserlambda
Junior Developer
Junior Developer
 
Posts: 15
Joined: Mon Mar 28, 2011 10:43 am

Re: Fail to connect to camera service

Postby raj_J2ME » Tue Mar 29, 2011 12:44 pm

Are you properly releasing all the camera related stuff?
Call release() to release the camera for use by other applications. Applications should release the camera immediately in onPause() (and re-open() it in onResume().

Check and revert.
Thanks with Regards,
Raj - The Kernel
raj_J2ME
Master Developer
Master Developer
 
Posts: 311
Joined: Tue Feb 15, 2011 7:40 am
Location: The Capital of India,

Re: Fail to connect to camera service

Postby macuserlambda » Tue Mar 29, 2011 2:58 pm

Thanks !!

I was doing :
camera = null;
instead of :
camera.release();
Last edited by macuserlambda on Tue Mar 29, 2011 3:14 pm, edited 1 time in total.
macuserlambda
Junior Developer
Junior Developer
 
Posts: 15
Joined: Mon Mar 28, 2011 10:43 am

Re: [Solved] Fail to connect to camera service

Postby macuserlambda » Tue Mar 29, 2011 3:02 pm

How can I set this thread as resolved ? I'm new member of anddev.org :-)
macuserlambda
Junior Developer
Junior Developer
 
Posts: 15
Joined: Mon Mar 28, 2011 10:43 am

Top

Re: [Solved] Fail to connect to camera service

Postby macuserlambda » Tue Mar 29, 2011 3:09 pm

Just an other question about my second issue exposed in my previous post :

Why onResume() is called in my first tab activity, when I press back button in the activity created from my second tab ?
macuserlambda
Junior Developer
Junior Developer
 
Posts: 15
Joined: Mon Mar 28, 2011 10:43 am

Re: Fail to connect to camera service

Postby raj_J2ME » Tue Mar 29, 2011 7:00 pm

macuserlambda wrote:Thanks !!

I was doing :
camera = null;
instead of :
camera.release();


Okay, you have done a great job.. :)
Well we must always release the resources whatever we have occupied from the system as soon as possible and as following the best way as possible. The way you were releasing the camera was improper and hence it was causing such a critical issue.
Thanks with Regards,
Raj - The Kernel
raj_J2ME
Master Developer
Master Developer
 
Posts: 311
Joined: Tue Feb 15, 2011 7:40 am
Location: The Capital of India,

Re: [Solved] Fail to connect to camera service

Postby raj_J2ME » Tue Mar 29, 2011 7:09 pm

macuserlambda wrote:Just an other question about my second issue exposed in my previous post :

Why onResume() is called in my first tab activity, when I press back button in the activity created from my second tab ?

You need to understand the Activity life cycle clearly and the you will understand the flow of called methods. Please refer this link to understand the same.
http://developer.android.com/reference/android/app/Activity.html
Thanks with Regards,
Raj - The Kernel
raj_J2ME
Master Developer
Master Developer
 
Posts: 311
Joined: Tue Feb 15, 2011 7:40 am
Location: The Capital of India,

Re: [Solved] Fail to connect to camera service

Postby macuserlambda » Wed Mar 30, 2011 11:57 am

raj_J2ME wrote:You need to understand the Activity life cycle clearly and the you will understand the flow of called methods. Please refer this link to understand the same.
http://developer.android.com/reference/android/app/Activity.html


Thanks again for your answer ! :D

I think I understand, I read this link before. But I don't understand in this case, with my TabHost. :P

In iOS, I'm doing the same thing. I have an UITabBarController which contains three UIViewControllers. When I'm in the second tab, I call presentModalViewController to show a new UIViewController in fullscreen. When I dismiss this new UIViewController, viewWillAppear method is called only in the second tab as expected. The one of first or third tab is not called.

In Android, when I create a new Intent and start activity in the second tab, onResume is called in the first tab. Despite the fact that it's the second one which appears...

Moreover, onPause method of the first tab is called when I switch to second tab, which means I leave the first Activity and onResume should be called only when I switch back to the first tab.

I'm french, it's difficult for me to explain that in english so I hope I make myself clear... :)
macuserlambda
Junior Developer
Junior Developer
 
Posts: 15
Joined: Mon Mar 28, 2011 10:43 am

Re: [Solved] Fail to connect to camera service

Postby macuserlambda » Mon Apr 04, 2011 8:30 am

Nobody could help me ? :?
macuserlambda
Junior Developer
Junior Developer
 
Posts: 15
Joined: Mon Mar 28, 2011 10:43 am

Re: [Solved] Fail to connect to camera service

Postby Athrum » Wed Apr 06, 2011 10:24 am

I have met the same problem, but the error only occurs when I turn back from Camera Applications. Manifest.xml is Ok and I used release() in onPause().
Athrum
Once Poster
Once Poster
 
Posts: 1
Joined: Wed Apr 06, 2011 3:10 am

Top

Return to SDK/ADT/Emulator Problems

Who is online

Users browsing this forum: No registered users and 6 guests