Fatal exception when click play button


#1

My HelloMoon app is crashing when I clicked play button.

Here is what I have in LogCat :

05-18 18:32:35.854: E/AndroidRuntime(7853): FATAL EXCEPTION: main
05-18 18:32:35.854: E/AndroidRuntime(7853): Process: com.bignerdranch.android.hellomoon, PID: 7853
05-18 18:32:35.854: E/AndroidRuntime(7853): java.lang.NullPointerException
05-18 18:32:35.854: E/AndroidRuntime(7853): at com.bignerdranch.android.hellomoon.AudioPlayer.play(AudioPlayer.java:23)
05-18 18:32:35.854: E/AndroidRuntime(7853): at com.bignerdranch.android.hellomoon.HelloMoonFragment$1.onClick(HelloMoonFragment.java:26)

Line 23 AudioPlayer:

23 mPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {

		@Override
		public void onCompletion(MediaPlayer mp) {
			stop();

		}
	});

	mPlayer.start();

}

Line 26 HelloMoonFragment:

	mPlayButton.setOnClickListener(new View.OnClickListener() {

		@Override
		public void onClick(View v) {

26 mPlayer.play(getActivity());
}
});

What can be happening?
Please help.


#2

Did you get neglect to set mPlayer? That is, is mPlayer null when line 23 executes?


#3

That was the problem. I forgot to set mPlayer. My mistake!!!