0

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)
asked Apr 25, 2013 at 5:45
3
  • Do you have any decorations in the manifest Activity declaration? Commented Apr 25, 2013 at 5:48
  • No, I havn't done anything with the manifest file! What else could be wrong? Commented Apr 25, 2013 at 6:03
  • what is happening in the GameLoop class at line 78? Commented Apr 25, 2013 at 6:41

2 Answers 2

2

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);
}
answered Apr 25, 2013 at 6:06
Sign up to request clarification or add additional context in comments.

4 Comments

Thanks, but this isn't helping anything :( I have done an application with this order that I have in my code before and that worked fine. So what could the the problem be? I can't continue with my works, it's so irritating
could you please update your question with complete logcat stacktrace?
Sorry, but now it seems like there is some other problem! Perhaps my first problem is solved, but my app still close!
you have nullpointerexception at line 78 in GameLoop.java. Check for any objects for null vales. If u can't solve it, open a new question because your original question has been salved
1

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);
}
answered Apr 25, 2013 at 6:09

1 Comment

No it isn't. Perhaps is some other problems

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.