我正在尝试开发一个应用程序。它有一些活动,它们是
SplashActivity
、、、
MainMenuActivity
和
GameActivity
。
现在,所有三个活动都扩展了BaseActivity
,这也扩展AndroidApplication
了 libgdx。
在SplashActivity
andMainMenuActivity
中,我使用 onCreate、setContentView 和布局等编写了纯 android 特定代码。我没有在这些活动上编写任何 libgdx 代码。
Activity 过渡是这样的,SplashActivity(完成)-> MainMenuActivity(未完成)-> GameActivity
在 GameActivity 上,我 setContentView 我的游戏布局,然后,编写以下代码:
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);
}
但是我在 SplashActivity 上遇到 RuntimeException,我不知道为什么,
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