[英]Error message that I can't solve
I'm getting this error message: requestFeature() must be called before adding content. 我收到此错误消息:在添加内容之前必须调用requestFeature()。 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().
我已经在stackowerflow上阅读了有关此错误消息的其他问题,如果我理解正确的话,那就是不要在requestFeature()之前调用setContentView()。 But isn't this what I have done in my onCreate method?
但这不是我在onCreate方法中所做的吗? 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 编辑: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);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.