I am developing a whack-a-mole game for android in eclipse. My app works on android 2.2 but not on newer versions. What happens is that the splashscreen loads fine and my main activity starts fine too, but to start the game you need to tap the first screen of the main activity. When you do that the emulator shows: "Unfortunately my app stopped"
I came across a similar question here, but I couldn't find out what I had to do if this was the problem in my code.
Logcat:
07-04 12:08:49.029: E/InputEventReceiver(2099): Exception dispatching input event.
07-04 12:08:49.049: E/MessageQueue-JNI(2099): Exception in MessageQueue callback: handleReceiveCallback
07-04 12:08:49.329: E/MessageQueue-JNI(2099): java.lang.NullPointerException
07-04 12:08:49.329: E/MessageQueue-JNI(2099): at android.graphics.Bitmap.createScaledBitmap(Bitmap.java:589)
07-04 12:08:49.329: E/MessageQueue-JNI(2099): at com.jellyproductions.holymoly.HolyMolyView$WhackAMoleThread.doTouchEvent(HolyMolyView.java:460)
07-04 12:08:49.329: E/MessageQueue-JNI(2099): at com.jellyproductions.holymoly.HolyMolyView.onTouchEvent(HolyMolyView.java:1691)
07-04 12:08:49.329: E/MessageQueue-JNI(2099): at android.view.View.dispatchTouchEvent(View.java:7706)
07-04 12:08:49.329: E/MessageQueue-JNI(2099): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
07-04 12:08:49.329: E/MessageQueue-JNI(2099): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959)
07-04 12:08:49.329: E/MessageQueue-JNI(2099): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
07-04 12:08:49.329: E/MessageQueue-JNI(2099): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959)
07-04 12:08:49.329: E/MessageQueue-JNI(2099): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
07-04 12:08:49.329: E/MessageQueue-JNI(2099): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959)
07-04 12:08:49.329: E/MessageQueue-JNI(2099): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
07-04 12:08:49.329: E/MessageQueue-JNI(2099): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959)
07-04 12:08:49.329: E/MessageQueue-JNI(2099): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:2068)
07-04 12:08:49.329: E/MessageQueue-JNI(2099): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1515)
07-04 12:08:49.329: E/MessageQueue-JNI(2099): at android.app.Activity.dispatchTouchEvent(Activity.java:2458)
07-04 12:08:49.329: E/MessageQueue-JNI(2099): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:2016)
07-04 12:08:49.329: E/MessageQueue-JNI(2099): at android.view.View.dispatchPointerEvent(View.java:7886)
07-04 12:08:49.329: E/MessageQueue-JNI(2099): at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:3954)
07-04 12:08:49.329: E/MessageQueue-JNI(2099): at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:3833)
07-04 12:08:49.329: E/MessageQueue-JNI(2099): at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3399)
07-04 12:08:49.329: E/MessageQueue-JNI(2099): at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3449)
07-04 12:08:49.329: E/MessageQueue-JNI(2099): at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3418)
07-04 12:08:49.329: E/MessageQueue-JNI(2099): at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3525)
07-04 12:08:49.329: E/MessageQueue-JNI(2099): at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3426)
07-04 12:08:49.329: E/MessageQueue-JNI(2099): at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:3582)
07-04 12:08:49.329: E/MessageQueue-JNI(2099): at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3399)
07-04 12:08:49.329: E/MessageQueue-JNI(2099): at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3449)
07-04 12:08:49.329: E/MessageQueue-JNI(2099): at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3418)
07-04 12:08:49.329: E/MessageQueue-JNI(2099): at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3426)
07-04 12:08:49.329: E/MessageQueue-JNI(2099): at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3399)
07-04 12:08:49.329: E/MessageQueue-JNI(2099): at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:5602)
07-04 12:08:49.329: E/MessageQueue-JNI(2099): at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:5582)
07-04 12:08:49.329: E/MessageQueue-JNI(2099): at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:5553)
07-04 12:08:49.329: E/MessageQueue-JNI(2099): at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:5682)
07-04 12:08:49.329: E/MessageQueue-JNI(2099): at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:185)
07-04 12:08:49.329: E/MessageQueue-JNI(2099): at android.os.MessageQueue.nativePollOnce(Native Method)
07-04 12:08:49.329: E/MessageQueue-JNI(2099): at android.os.MessageQueue.next(MessageQueue.java:138)
07-04 12:08:49.329: E/MessageQueue-JNI(2099): at android.os.Looper.loop(Looper.java:123)
07-04 12:08:49.329: E/MessageQueue-JNI(2099): at android.app.ActivityThread.main(ActivityThread.java:5017)
07-04 12:08:49.329: E/MessageQueue-JNI(2099): at java.lang.reflect.Method.invokeNative(Native Method)
07-04 12:08:49.329: E/MessageQueue-JNI(2099): at java.lang.reflect.Method.invoke(Method.java:515)
07-04 12:08:49.329: E/MessageQueue-JNI(2099): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
07-04 12:08:49.329: E/MessageQueue-JNI(2099): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
07-04 12:08:49.329: E/MessageQueue-JNI(2099): at dalvik.system.NativeStart.main(Native Method)
07-04 12:08:49.339: D/AndroidRuntime(2099): Shutting down VM
07-04 12:08:49.339: W/dalvikvm(2099): threadid=1: thread exiting with uncaught exception (group=0xb3a4cba8)
07-04 12:08:49.569: E/AndroidRuntime(2099): FATAL EXCEPTION: main
07-04 12:08:49.569: E/AndroidRuntime(2099): Process: com.jellyproductions.holymoly, PID: 2099
07-04 12:08:49.569: E/AndroidRuntime(2099): java.lang.NullPointerException
07-04 12:08:49.569: E/AndroidRuntime(2099): at android.graphics.Bitmap.createScaledBitmap(Bitmap.java:589)
07-04 12:08:49.569: E/AndroidRuntime(2099): at com.jellyproductions.holymoly.HolyMolyView$WhackAMoleThread.doTouchEvent(HolyMolyView.java:460)
07-04 12:08:49.569: E/AndroidRuntime(2099): at com.jellyproductions.holymoly.HolyMolyView.onTouchEvent(HolyMolyView.java:1691)
07-04 12:08:49.569: E/AndroidRuntime(2099): at android.view.View.dispatchTouchEvent(View.java:7706)
07-04 12:08:49.569: E/AndroidRuntime(2099): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
07-04 12:08:49.569: E/AndroidRuntime(2099): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959)
07-04 12:08:49.569: E/AndroidRuntime(2099): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
07-04 12:08:49.569: E/AndroidRuntime(2099): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959)
07-04 12:08:49.569: E/AndroidRuntime(2099): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
07-04 12:08:49.569: E/AndroidRuntime(2099): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959)
07-04 12:08:49.569: E/AndroidRuntime(2099): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
07-04 12:08:49.569: E/AndroidRuntime(2099): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959)
07-04 12:08:49.569: E/AndroidRuntime(2099): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:2068)
07-04 12:08:49.569: E/AndroidRuntime(2099): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1515)
07-04 12:08:49.569: E/AndroidRuntime(2099): at android.app.Activity.dispatchTouchEvent(Activity.java:2458)
07-04 12:08:49.569: E/AndroidRuntime(2099): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:2016)
07-04 12:08:49.569: E/AndroidRuntime(2099): at android.view.View.dispatchPointerEvent(View.java:7886)
07-04 12:08:49.569: E/AndroidRuntime(2099): at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:3954)
07-04 12:08:49.569: E/AndroidRuntime(2099): at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:3833)
07-04 12:08:49.569: E/AndroidRuntime(2099): at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3399)
07-04 12:08:49.569: E/AndroidRuntime(2099): at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3449)
07-04 12:08:49.569: E/AndroidRuntime(2099): at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3418)
07-04 12:08:49.569: E/AndroidRuntime(2099): at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3525)
07-04 12:08:49.569: E/AndroidRuntime(2099): at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3426)
07-04 12:08:49.569: E/AndroidRuntime(2099): at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:3582)
07-04 12:08:49.569: E/AndroidRuntime(2099): at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3399)
07-04 12:08:49.569: E/AndroidRuntime(2099): at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3449)
07-04 12:08:49.569: E/AndroidRuntime(2099): at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3418)
07-04 12:08:49.569: E/AndroidRuntime(2099): at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3426)
07-04 12:08:49.569: E/AndroidRuntime(2099): at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3399)
07-04 12:08:49.569: E/AndroidRuntime(2099): at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:5602)
07-04 12:08:49.569: E/AndroidRuntime(2099): at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:5582)
07-04 12:08:49.569: E/AndroidRuntime(2099): at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:5553)
07-04 12:08:49.569: E/AndroidRuntime(2099): at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:5682)
07-04 12:08:49.569: E/AndroidRuntime(2099): at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:185)
07-04 12:08:49.569: E/AndroidRuntime(2099): at android.os.MessageQueue.nativePollOnce(Native Method)
07-04 12:08:49.569: E/AndroidRuntime(2099): at android.os.MessageQueue.next(MessageQueue.java:138)
07-04 12:08:49.569: E/AndroidRuntime(2099): at android.os.Looper.loop(Looper.java:123)
07-04 12:08:49.569: E/AndroidRuntime(2099): at android.app.ActivityThread.main(ActivityThread.java:5017)
07-04 12:08:49.569: E/AndroidRuntime(2099): at java.lang.reflect.Method.invokeNative(Native Method)
07-04 12:08:49.569: E/AndroidRuntime(2099): at java.lang.reflect.Method.invoke(Method.java:515)
07-04 12:08:49.569: E/AndroidRuntime(2099): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
07-04 12:08:49.569: E/AndroidRuntime(2099): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
07-04 12:08:49.569: E/AndroidRuntime(2099): at dalvik.system.NativeStart.main(Native Method)
DoTouchEvent Method:
boolean doTouchEvent(MotionEvent event) {
synchronized (mySurfaceHolder) {
int eventaction = event.getAction();
int X = (int) event.getX();
int Y = (int) event.getY();
switch (eventaction) {
case MotionEvent.ACTION_DOWN:
if (!gameOver) {
fingerX = X;
fingerY = Y;
if (!onTitle && detectMoleHit()) {
whacking = true;
molesWhacked++;
if (molesWhacked < highscore) {
highscore = highscore;
} else if (molesWhacked == highscore) {
molesWhacked = highscore;
} else if (molesWhacked > highscore) {
highscore++;
}
}
}
break;
case MotionEvent.ACTION_MOVE:
break;
case MotionEvent.ACTION_UP:
if (onTitle || gameOver || gameOverRed || gameOverBlue
|| gameOverGreen || gameOverPink || gameOverYellow) {
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
backgroundImg = BitmapFactory.decodeResource(
myContext.getResources(),
R.drawable.background, options);
backgroundImg = Bitmap.createScaledBitmap( **//Line 460**
backgroundImg, screenW, screenH, true);
maskup = BitmapFactory.decodeResource(
myContext.getResources(), R.drawable.maskup,
options);
maskmiddle = BitmapFactory.decodeResource(
myContext.getResources(),
R.drawable.maskmiddle, options);
maskdown = BitmapFactory.decodeResource(
myContext.getResources(), R.drawable.maskdown,
options);
molered = BitmapFactory.decodeResource(
myContext.getResources(), R.drawable.molered,
options);
moleblue = BitmapFactory.decodeResource(
myContext.getResources(), R.drawable.moleblue,
options);
molegreen = BitmapFactory.decodeResource(
myContext.getResources(), R.drawable.molegreen,
options);
molepink = BitmapFactory.decodeResource(
myContext.getResources(), R.drawable.molepink,
options);
moleyellow = BitmapFactory.decodeResource(
myContext.getResources(),
R.drawable.moleyellow, options);
whack = BitmapFactory.decodeResource(
myContext.getResources(), R.drawable.whack,
options);
gameoverred = BitmapFactory.decodeResource(
myContext.getResources(),
R.drawable.gameoverred, options);
gameoverblue = BitmapFactory.decodeResource(
myContext.getResources(),
R.drawable.gameoverblue, options);
gameovergreen = BitmapFactory.decodeResource(
myContext.getResources(),
R.drawable.gameovergreen, options);
gameoverpink = BitmapFactory.decodeResource(
myContext.getResources(),
R.drawable.gameoverpink, options);
gameoveryellow = BitmapFactory.decodeResource(
myContext.getResources(),
R.drawable.gameoveryellow, options);
scaleW = (float) screenW / (float) backgroundOrigW;
scaleH = (float) screenH / (float) backgroundOrigH;
maskup = Bitmap.createScaledBitmap(maskup,
(int) (maskup.getWidth() * scaleW),
(int) (maskup.getHeight() * scaleH), true);
maskmiddle = Bitmap.createScaledBitmap(maskmiddle,
(int) (maskmiddle.getWidth() * scaleW),
(int) (maskmiddle.getHeight() * scaleH), true);
maskdown = Bitmap.createScaledBitmap(maskdown,
(int) (maskdown.getWidth() * scaleW),
(int) (maskdown.getHeight() * scaleH), true);
molered = Bitmap.createScaledBitmap(molered,
(int) (molered.getWidth() * scaleW),
(int) (molered.getHeight() * scaleH), true);
moleblue = Bitmap.createScaledBitmap(moleblue,
(int) (moleblue.getWidth() * scaleW),
(int) (moleblue.getHeight() * scaleH), true);
molegreen = Bitmap.createScaledBitmap(molegreen,
(int) (molegreen.getWidth() * scaleW),
(int) (molegreen.getHeight() * scaleH), true);
molepink = Bitmap.createScaledBitmap(molepink,
(int) (molepink.getWidth() * scaleW),
(int) (molepink.getHeight() * scaleH), true);
moleyellow = Bitmap.createScaledBitmap(moleyellow,
(int) (moleyellow.getWidth() * scaleW),
(int) (moleyellow.getHeight() * scaleH), true);
whack = Bitmap.createScaledBitmap(whack,
(int) (whack.getWidth() * scaleW),
(int) (whack.getHeight() * scaleH), true);
gameoverred = Bitmap.createScaledBitmap(gameoverred,
screenW, screenH, true);
gameoverblue = Bitmap.createScaledBitmap(gameoverblue,
screenW, screenH, true);
gameovergreen = Bitmap.createScaledBitmap(
gameovergreen, screenW, screenH, true);
gameoverpink = Bitmap.createScaledBitmap(gameoverpink,
screenW, screenH, true);
gameoveryellow = Bitmap.createScaledBitmap(
gameoveryellow, screenW, screenH, true);
onTitle = false;
pickMole();
}
whacking = false;
if (gameOver || gameOverRed || gameOverBlue
|| gameOverGreen || gameOverPink || gameOverYellow) {
if (molesWhacked > highscore) {
molesWhacked = highscore;
} else if (molesWhacked == highscore) {
molesWhacked = highscore;
} else if (molesWhacked < highscore) {
highscore = highscore;
}
molesWhacked = 0;
molesMissed = 0;
activeMoleR = 0;
activeMoleB = 0;
activeMoleG = 0;
activeMoleP = 0;
activeMoleY = 0;
pickMoleColor();
gameOver = false;
gameOverRed = false;
gameOverBlue = false;
gameOverGreen = false;
gameOverPink = false;
gameOverYellow = false;
pickMole();
}
break;
} **//Line 589**
}
return true;
}
OnTouchEvent Method:
@Override
public boolean onTouchEvent(MotionEvent event) {
return thread.doTouchEvent(event); **//Line 1691**
}
Main Actvity XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<com.jellyproductions.holymoly.HolyMolyView
android:id="@+id/mole"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
<com.google.ads.AdView android:id="@+id/adView"
android:layout_width="350dp"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
ads:adUnitId=".............."
ads:adSize="BANNER"
ads:testDevices="TEST_EMULATOR, TEST_DEVICE_ID"
ads:loadAdOnCreate="true"/>
I have noticed that some people said that I have set a variable to null, which it shouldn't be, but I think I haven't done that. I really am struggling with what I have to do now and I have been searching google and SO for other questions/posts related to this subject, but I still haven't found a solution...