takePicture "Unfortunately, CriminalIntent has stopped"


#1

This morning I started working on chapter 20 where we start with implementing the callbacks for takePicture(…)

After implementing these callbacks and adding the call to takePicture(…) i tested the app. Pressing the ‘Take picture’ button now makes the app crash, “Unfortunately, CriminalIntent has stopped”.
Below are the error messages form the log. This happens even when i remove all code from both onShutter() and onPictureTaken(…) and have the following in the onClick event of the takePictureButton:

[code]public void onClick(View v) {

//getActivity().finish();
if (mCamera != null)
	mCamera.takePicture(mShutterCallback, null, mJpegCallback);
getActivity().finish();

}[/code]

Here is the log:

07-11 07:25:08.470: W/dalvikvm(4492): threadid=1: thread exiting with uncaught exception (group=0x40a71930) 07-11 07:25:08.500: E/AndroidRuntime(4492): FATAL EXCEPTION: main 07-11 07:25:08.500: E/AndroidRuntime(4492): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.bignerdranch.android.criminalintent/com.bignerdranch.android.criminalintent.CrimePagerActivity}: java.lang.NullPointerException 07-11 07:25:08.500: E/AndroidRuntime(4492): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180) 07-11 07:25:08.500: E/AndroidRuntime(4492): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230) 07-11 07:25:08.500: E/AndroidRuntime(4492): at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:3692) 07-11 07:25:08.500: E/AndroidRuntime(4492): at android.app.ActivityThread.access$700(ActivityThread.java:141) 07-11 07:25:08.500: E/AndroidRuntime(4492): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1240) 07-11 07:25:08.500: E/AndroidRuntime(4492): at android.os.Handler.dispatchMessage(Handler.java:99) 07-11 07:25:08.500: E/AndroidRuntime(4492): at android.os.Looper.loop(Looper.java:137) 07-11 07:25:08.500: E/AndroidRuntime(4492): at android.app.ActivityThread.main(ActivityThread.java:5041) 07-11 07:25:08.500: E/AndroidRuntime(4492): at java.lang.reflect.Method.invokeNative(Native Method) 07-11 07:25:08.500: E/AndroidRuntime(4492): at java.lang.reflect.Method.invoke(Method.java:511) 07-11 07:25:08.500: E/AndroidRuntime(4492): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793) 07-11 07:25:08.500: E/AndroidRuntime(4492): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560) 07-11 07:25:08.500: E/AndroidRuntime(4492): at dalvik.system.NativeStart.main(Native Method) 07-11 07:25:08.500: E/AndroidRuntime(4492): Caused by: java.lang.NullPointerException 07-11 07:25:08.500: E/AndroidRuntime(4492): at com.bignerdranch.android.criminalintent.CrimeFragment.onCreateView(CrimeFragment.java:126) 07-11 07:25:08.500: E/AndroidRuntime(4492): at android.support.v4.app.Fragment.performCreateView(Fragment.java:1460) 07-11 07:25:08.500: E/AndroidRuntime(4492): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:911) 07-11 07:25:08.500: E/AndroidRuntime(4492): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1088) 07-11 07:25:08.500: E/AndroidRuntime(4492): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1070) 07-11 07:25:08.500: E/AndroidRuntime(4492): at android.support.v4.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:1861) 07-11 07:25:08.500: E/AndroidRuntime(4492): at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:547) 07-11 07:25:08.500: E/AndroidRuntime(4492): at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1164) 07-11 07:25:08.500: E/AndroidRuntime(4492): at android.app.Activity.performStart(Activity.java:5114) 07-11 07:25:08.500: E/AndroidRuntime(4492): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2153) 07-11 07:25:08.500: E/AndroidRuntime(4492): ... 12 more


#2

I’m getting the same error.


#3

Brabbeldas - can you show line 126 of CrimeFragment.java? That’s where your exception is occurring - a value is null there.


#4

I think I found it. For me I wanted to leave the time logic in my app. I had both TIME and PHOTO initialized to “1”. I changed PHOTO to “2” and it started to work correctly.

private static final int REQUEST_DATE = 0; private static final int REQUEST_TIME = 1; private static final int REQUEST_PHOTO = 2;


#5

I also commented out the above “getActivity().finish();” code