Tyde
Tyde

Reputation: 343

Error: "requestFeature() must be called before adding content", although it is called before setContentView()

I have an Activity which uses the ActionBarSherlock. Now I wanted to show an Indeterminate Progress in that actionbar and followed the example from ActionBarSherlock:

public class MainMenu extends SimpleWebActivity implements BackgroundBrowserReciever {
    private Boolean windowFeatureCalled;


    @Override
    public void onCreate(Bundle savedInstanceState) {
        requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
        super.onCreate(savedInstanceState);

        this.windowFeatureCalled = true;
        setContentView(R.layout.main_menu);
                ....
    }

The SimpleWebActivity is an abstract class which extends a SherlockActivity.

But when I try to load that Activity, I get the following error:

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.dalthed.tucan/com.dalthed.tucan.ui.MainMenu}: android.util.AndroidRuntimeException: requestFeature() must be called before adding content

Why does this error occur, even when i request that WindowFeature before calling setContentView?

Upvotes: 1

Views: 3194

Answers (2)

Manoj Kumar
Manoj Kumar

Reputation: 177

Lets try this it works for me

@Override
    public void onCreate(Bundle savedInstanceState) {

//HERE
        requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);

        super.onCreate(savedInstanceState);

        setContentView(R.layout.main_menu);

         this.windowFeatureCalled = true;
                ....
    }

Upvotes: 1

Broak
Broak

Reputation: 4187

Move it after your Super.onCreate, that should resolve your issue.

     @Override
        public void onCreate(Bundle savedInstanceState) {

            super.onCreate(savedInstanceState);

//HERE
 requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);

            setContentView(R.layout.main_menu);
  this.windowFeatureCalled = true;
                    ....
        }

Upvotes: 5

Related Questions