2013-05-27 86 views
3

我嘗試開發一個應用程序。它有一些活動,它們是: SplashActivity, MainMenuActivityGameActivity無法恢復在libGDX中的活動

現在,所有三項活動延伸到BaseActivity,這也擴展了libgdx的AndroidApplication

SplashActivityMainMenuActivity,我寫了純粹的android特定的代碼,使用onCreate,setContentView佈局等。我沒有在這些活動上寫任何libgdx代碼。

活動轉變是這樣的, SplashActivity(它得到完成) - > MainMenuActivity(不拿完) - > GameActivity

上,GameActivity,我的setContentView mygame佈局,並寫這樣的代碼:

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 
+0

正如PT說,你的SplashActivity沒有初始化libgdx,你可以看到AndroidApplication的第249行是((AndroidInput)getInput())。registerSensorListeners();當你調用AndroidApplication#initialize(..)在SplashActivity#onCreate()中調用,這就是拋出NullPointerException的原因。 –

回答

2

堆棧跟蹤的這一部分:

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) 

意味着你的SplashActivity擴展Libgdx AndroidApplication。但是,你寫道:

在SplashActivity,MainMenuActivity,我一直在使用的onCreate書面純的Android 特定代碼,的setContentView佈局等我有 沒有寫上活動的任何libgdx代碼。

但是,如果你正在擴展AndroidApplication,你會得到一堆在暫停和恢復時運行的Libgdx代碼。可是你有沒有初始化Libgdx,但(因爲這似乎發生,因爲你的GameActivity的創作的副作用。

保持你的Android純正純粹的活動,並且不延長Libgdx類。