Black Screen


#1

After entering all code in Chapter 19, I get a black screen next to the Take button when I hit the camera icon. My problem is that the mCamera variable is null. My onResume() method with debug logging follows:

@TargetApi(9)
 @Override
public void onResume() {
	 super.onResume();
	if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) {
		 mCamera.open(0);
		 Log.d(TAG, "*** new OS with mCamera: " + mCamera);
	 } else {
		 mCamera = Camera.open();
		 Log.d(TAG, "*** old OS with mCamera: " + mCamera);
	}
}

I have a new Nexus 7 with two cameras and have tried using both 0 and 1 as the mCamera.open() argument. The results are the same –

    04-12 18:11:27.331: D/CrimeCameraFragment(8748): *** new OS with mCamera: null

Thanks for any suggestions.


#2

Here are my results with Nexus devices:
[ul]
Nexus 5 (2 cameras): Worked and used rear camera
Nexus 7 2012 (1 camera): Worked.
Nexus 7 2013 (2 cameras): Worked and used rear camera
[/ul]


#3

I had a black screen issue as well, though all the code was correct.
Then I tried the following snippet to open camera:

		[code]if(Build.VERSION.SDK_INT > Build.VERSION_CODES.FROYO) { mCamera = Camera.open(0);}
		else {	mCamera = Camera.open();	}[/code]

Although it has the same logic as code piece listed in the book, it worked for me. Both front and rear cameras worked fine.

Then for the sake of experiment I switched back to authors’ code and it worked as well. Bug?

Hope it helps.