When i try to click on the button several time then i encountered this error. Below are the error in logcat:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.huiiy.myapplication, PID: 3933
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.media.MediaPlayer.start()' on a null object reference
at com.example.huiiy.myapplication.Activity9$13.onClick(Activity9.java:288)
at android.view.View.performClick(View.java:5712)
at android.view.View$PerformClick.run(View.java:22514)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6141)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
Below are the coding of my application:
iv_33.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
MediaPlayer ivbsound = new MediaPlayer();
ivbsound = MediaPlayer.create(Activity9.this,R.raw.ivbutton);
// MediaPlayer ivbsound = MediaPlayer.create(Activity9.this,R.raw.ivbutton);
ivbsound.start();
int theCard = Integer.parseInt((String) view.getTag());
doStuff(iv_33, theCard);
}
});