Reputation: 126
I am try to develop an application. It has some activities, these are,
SplashActivity
,
MainMenuActivity
, and
GameActivity
.
Now, all three activities extends BaseActivity
which also extends AndroidApplication
of libgdx.
In SplashActivity
and MainMenuActivity
, I have written pure android specific code using onCreate, setContentView a layout and etc. I have not write any libgdx code on those activites.
Activity transitions are like this, SplashActivity (it gets finish) -> MainMenuActivity (not get finished) -> GameActivity
On, GameActivity, I setContentView mygame layout, and, write this code:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mygame);
gbbrdlyot1 = (RelativeLayout) findViewById(R.id.gbbrdlyot1);
gameBoard = new RelativeLayout(this);
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(newBlockWidth, newBlockWidth);
gameBoard.setLayoutParams(layoutParams);
View gameView = initializeForView(new GameView(), true);
gameBoard.addView(gameView);
gbbrdlyot1.addView(gameBoard);
}
But I am getting RuntimeException on SplashActivity, I dont know why,
05-27 12:56:22.609: java.lang.RuntimeException: Unable to resume activity com.game.MyGame/com.game.MyGame.SplashActivity}: java.lang.NullPointerException
05-27 12:56:22.609: at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2124)
05-27 12:56:22.609: at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2139)
05-27 12:56:22.609: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1672)
05-27 12:56:22.609: at android.app.ActivityThread.access$1500(ActivityThread.java:117)
05-27 12:56:22.609: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
05-27 12:56:22.609: at android.os.Handler.dispatchMessage(Handler.java:99)
05-27 12:56:22.609: at android.os.Looper.loop(Looper.java:130)
05-27 12:56:22.609: at android.app.ActivityThread.main(ActivityThread.java:3687)
05-27 12:56:22.609: at java.lang.reflect.Method.invokeNative(Native Method)
05-27 12:56:22.609: at java.lang.reflect.Method.invoke(Method.java:507)
05-27 12:56:22.609: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
05-27 12:56:22.609: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
05-27 12:56:22.609: at dalvik.system.NativeStart.main(Native Method)
05-27 12:56:22.609: Caused by: java.lang.NullPointerException
05-27 12:56:22.609: at com.badlogic.gdx.backends.android.AndroidApplication.onResume(AndroidApplication.java:249)
05-27 12:56:22.609: at com.game.MyGame.SplashActivity.onResume(SplashActivity.java:43)
05-27 12:56:22.609: at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1150)
05-27 12:56:22.609: at android.app.Activity.performResume(Activity.java:3832)
05-27 12:56:22.609: at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2114)
05-27 12:56:22.609: ... 12 more
Upvotes: 2
Views: 1411
Reputation: 25177
This part of the stack trace:
05-27 12:56:22.609: Caused by: java.lang.NullPointerException
05-27 12:56:22.609: at com.badlogic.gdx.backends.android.AndroidApplication.onResume(AndroidApplication.java:249)
05-27 12:56:22.609: at com.game.MyGame.SplashActivity.onResume(SplashActivity.java:43)
Implies that your SplashActivity
extends the Libgdx AndroidApplication
. But you wrote:
In SplashActivity, MainMenuActivity, I have written pure android specific code using onCreate, setcontentView a layout and etc. I have not write any libgdx code on that activities.
But, if you're extending AndroidApplication
you're getting a bunch of Libgdx code that runs at pause and resume time. But you haven't initialized Libgdx yet (since that seems to happen as a side-effect of your GameActivity
's creation.
Keep your pure Android activities pure, and do not extend the Libgdx classes.
Upvotes: 2