I know this question is already been asked on stack but i tried all the solutions but of no use.Still i'm getting the same below error

Caused by: android.util.AndroidRuntimeException: requestFeature() must be called before adding content

below is code-

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        **requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);**  
        setContentView(R.layout.info);
        getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.window_title);
     }

I tried many links like given below- https://stackoverflow.com/search?q=requestFeature%28%29+must+be+called+before+adding+content

is there any solution???

2

There are 2 best solutions below

1
On

try this

@Override
    protected void onCreate(Bundle savedInstanceState) {

        requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
        getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.window_title);
        super.onCreate(savedInstanceState);
        setContentView(R.layout.info);

     }
0
On

Have you tried this..

@Override
protected void onCreate(Bundle savedInstanceState) {
    requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);  
    super.onCreate(savedInstanceState);   
    getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.window_title);     
    setContentView(R.layout.info);        
 }