I'm getting this error message: requestFeature() must be called before adding content. I have read other questions about this error message here at stackowerflow, and if I understand it correct, it's all about don't call setContentView() before requestFeature(). But isn't this what I have done in my onCreate method? Or could the error have to do with something else? I'm confused and would preciate some help to solve this error! Thanks!
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.activity_main);
// Set screen to landscape
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
// Remove title from screen
requestWindowFeature(Window.FEATURE_NO_TITLE);
// Set screen to full screen
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
// Create a new object of GameLoop and pass this context
gameLoop = new GameLoop(this);
gameLoop.setOnTouchListener(this);
setContentView(gameLoop);
}
EDIT: The LogCat
04-25 08:19:07.937: I/ApplicationPackageManager(6365): cscCountry is not German : NEE
04-25 08:19:08.085: W/dalvikvm(6365): threadid=9: thread exiting with uncaught exception (group=0x40018578)
04-25 08:19:08.101: E/AndroidRuntime(6365): FATAL EXCEPTION: Thread-10
04-25 08:19:08.101: E/AndroidRuntime(6365): java.lang.NullPointerException
04-25 08:19:08.101: E/AndroidRuntime(6365): at com.android.mergemania.GameLoop.drawObjects(GameLoop.java:78)
04-25 08:19:08.101: E/AndroidRuntime(6365): at com.android.mergemania.GameLoop.run(GameLoop.java:63)
04-25 08:19:08.101: E/AndroidRuntime(6365): at java.lang.Thread.run(Thread.java:1019)
You must set the orientation after requesting window feature. your statements must be in the below order
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
// Remove title from screen
requestWindowFeature(Window.FEATURE_NO_TITLE);
// Set screen to full screen
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
// Set screen to landscape
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
// Create a new object of GameLoop and pass this context
gameLoop = new GameLoop(this);
gameLoop.setOnTouchListener(this);
setContentView(gameLoop);
}
try for this:
protected void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);
//setContentView(R.layout.activity_main);
// Set screen to landscape
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
// Remove title from screen
// Set screen to full screen
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
// Create a new object of GameLoop and pass this context
gameLoop = new GameLoop(this);
gameLoop.setOnTouchListener(this);
setContentView(gameLoop);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.