Matthew
Matthew

Reputation: 3946

Camera.open() returns NULL Android development

I am following the tutorial for building a camera app http://developer.android.com/tools/device.html and I am my call to Camera.open() returns null. I've declared the permission in the manifest and I tried both on the emulator and a xyboard and I am still getting null. Does anyone know any quick hints?

Camera c = null;
try
{
    c = Camera.open()
}
catch(Exeption e)
{

}
return c;

Keep in mind, I am not throwing an exception, I am simply getting NULL back.

Upvotes: 3

Views: 8090

Answers (3)

Matthew
Matthew

Reputation: 3946

In order to get this working, I had to use the Camera.open(0) which meant that I had to change the API level in the manifest from 8 to 9. I am now getting an Error 100 though...

Upvotes: 0

Izkata
Izkata

Reputation: 9313

That's because it's not supposed to throw an exception. It returns null when no back-facing camera is found:

Creates a new Camera object to access the first back-facing camera on the device. If the device does not have a back-facing camera, this returns null.

You may be trying to access a front-facing camera, in which case you probably want to use open(int cameraId). (See the other answer for an example of using it)

Upvotes: 4

petey
petey

Reputation: 17140

Here is a really great tutorial for working with the android camera
You'll notice thru out the code there are toasts/alerts that will help guide you to what is happening

Upvotes: 2

Related Questions