簡體   English   中英

我無法解決的錯誤消息

[英]Error message that I can't solve

我收到此錯誤消息:在添加內容之前必須調用requestFeature()。 我已經在stackowerflow上閱讀了有關此錯誤消息的其他問題,如果我理解正確的話,那就是不要在requestFeature()之前調用setContentView()。 但這不是我在onCreate方法中所做的嗎? 還是該錯誤可能與其他原因有關? 我很困惑,希望能提供一些幫助來解決此錯誤! 謝謝!

    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);
}

編輯: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)

請求窗口功能后必須設置方向。 您的陳述必須按以下順序

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);
}

為此嘗試:

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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM