• Register
0 votes
148 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);

 

8 4 2
2,300 points

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.

5 2 1
4,980 points

Related questions

0 votes
1 answer 137 views
0 votes
1 answer 36 views
36 views
Cannot create controller in thread that did not call Looper.prepare () What does the following exception mean? How can I fix it? Here is the code: Toast toast = Toast.makeText (mContext, "Something", Toast.LENGTH_SHORT); This is the exception: Java.lang.RuntimeException: Cannot ... :121)      on Android.widget.Toast. <init> (Toast.Java:68)      on Android.widget.Toast.makeText (Toast.Java:231)
asked Aug 17 game 4.6k points
0 votes
1 answer 4 views
0 votes
1 answer 5 views
0 votes
1 answer 6 views