When an object collides with the other, it has to send it to another page with Intent, but it throws it from the application, I get a timer nullpointer exception error in logcat records. How can I fix this problem? I described it as follows ;
private Timer timer = new Timer();
private Handler handler = new Handler();
the part to throw on the other page :
int ordekMerkezX = ordekX + ordek.getWidth()/2 ;
int ordekMerkezY = ordekY + ordek.getHeight()/2;
if(0 <= ordekMerkezX && ordekMerkezX <= hikoGenisligi && hikoY <= ordekMerkezY && ordekMerkezY <= hikoY+hikoYuksekligi){
final MediaPlayer ses = MediaPlayer.create(this, R.raw.hikoses);
ses.start();
timer.cancel();
timer = null ;
Intent intent = new Intent(OyunEkrani.this , SonucEkrani.class);
startActivity(intent);
}
Logcat :
Process: com.mec.hikobabarun, PID: 7763
java.lang.NullPointerException: Attempt to invoke virtual method 'void java.util.Timer.cancel()' on a null object reference
at com.mec.hikobabarun.OyunEkrani.carpismaKontrol(OyunEkrani.java:227)
at com.mec.hikobabarun.OyunEkrani$1$1$1.run(OyunEkrani.java:113)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)