Hello all,
I tried to find an answer online for this problem, but i cannot find a way to fix my problem...
So maybe some of you guys know what i can do to solve it.
So i have a game ( surface view and thread that draws on the cavnas and all that gamy stuff ) and everything works fine in portrait mode, but i want my game to be played in landscape mode, so i have changed the mode in the android manifest like so:
android:screenOrientation="landscape"
Which works fine, everything is the same, except when i want to close the activity ( call onPause method ). When i get the error that the app needs to be force closed.
Now some people solved their problem by adding
android:configChanges="orientation|screenSize|keyboard|keyboardHidden|navigation"
To their manifest files, but that doesn't do the trick for me, i still keep getting NullPointerException
.
Here is the logcat:
07-24 21:27:12.160: E/AndroidRuntime(5272): FATAL EXCEPTION: main
07-24 21:27:12.160: E/AndroidRuntime(5272): java.lang.RuntimeException: Unable to pause activity {com.example.fishtruck/com.example.fishtruck.Start}: java.lang.NullPointerException
07-24 21:27:12.160: E/AndroidRuntime(5272): at android.app.ActivityThread.performPauseActivity(ActivityThread.java:2706)
07-24 21:27:12.160: E/AndroidRuntime(5272): at android.app.ActivityThread.performPauseActivity(ActivityThread.java:2662)
07-24 21:27:12.160: E/AndroidRuntime(5272): at android.app.ActivityThread.handlePauseActivity(ActivityThread.java:2640)
07-24 21:27:12.160: E/AndroidRuntime(5272): at android.app.ActivityThread.access$800(ActivityThread.java:123)
07-24 21:27:12.160: E/AndroidRuntime(5272): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1154)
07-24 21:27:12.160: E/AndroidRuntime(5272): at android.os.Handler.dispatchMessage(Handler.java:99)
07-24 21:27:12.160: E/AndroidRuntime(5272): at android.os.Looper.loop(Looper.java:137)
07-24 21:27:12.160: E/AndroidRuntime(5272): at android.app.ActivityThread.main(ActivityThread.java:4424)
07-24 21:27:12.160: E/AndroidRuntime(5272): at java.lang.reflect.Method.invokeNative(Native Method)
07-24 21:27:12.160: E/AndroidRuntime(5272): at java.lang.reflect.Method.invoke(Method.java:511)
07-24 21:27:12.160: E/AndroidRuntime(5272): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:825)
07-24 21:27:12.160: E/AndroidRuntime(5272): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:592)
07-24 21:27:12.160: E/AndroidRuntime(5272): at dalvik.system.NativeStart.main(Native Method)
07-24 21:27:12.160: E/AndroidRuntime(5272): Caused by: java.lang.NullPointerException
07-24 21:27:12.160: E/AndroidRuntime(5272): at com.example.fishtruck.Start.onPause(Start.java:113)
07-24 21:27:12.160: E/AndroidRuntime(5272): at android.app.Activity.performPause(Activity.java:4563)
07-24 21:27:12.160: E/AndroidRuntime(5272): at android.app.Instrumentation.callActivityOnPause(Instrumentation.java:1197)
07-24 21:27:12.160: E/AndroidRuntime(5272): at android.app.ActivityThread.performPauseActivity(ActivityThread.java:2693)
07-24 21:27:12.160: E/AndroidRuntime(5272): ... 12 more
And (not sure if relevant but what the heck ) here is how i call the onPause
method:
view.stopThread();
this.finish(); //this is called in the activity and view = surfaceView
And the stopThread()
method is called like so:
if(thread!=null){
thread.interrupt();
thread.setRunning(false);
isStopped = true;
thread = null;
}
What object do you have on row 113 in Start.java? The object you have there is not initiated correctly (it is null) which makes your app crash.