• Register
0 votes
562 views

Problem :

Currently I am facing below error very regularly

“ Android.util.AndroidRuntimeException: requestFeature() must be called before adding content” error.

If you can carefully see in my below code, my requestWindowFeature(Window.FEATURE_NO_TITLE); line is comming before the line setContentView(R.layout.mainmenu);.I never had any errors in my android code before until few days from now. Recently I had updated to ADT 22 and since then many random errors are popping up from everywhere. I have fixed many of those errors and this is by far the most difficult one.

Is there anybody who has fix on above error?

Below is my code:

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.mainmenu);

 

2.3k points

Please log in or register to answer this question.

1 Answer

0 votes

Solution :

I saw your question. I also faced this problem in the past but when I tried to call the window request just before calling the super.onCreate() and magically my problem was solved, You can also try it with the help of below code.

@Override
public void onCreate(Bundle savedInstanceState) {
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.mainmenu);
}

You can also hide your Status Bar on your Android 4.0 and Lower as below

<application

    ...

    android:theme="@android:style/Theme.Holo.NoActionBar.Fullscreen" >

    ...

</application>

You can use the activity theme for below reasons :

· It makes it very easy to maintain and also makes less error-prone than setting the flag programmatically.

· It makes the smoother UI transitions.

Hope this solution will help you.

5k points