-3
 @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_main);
}

crashes my app with the error

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

I know I have to request window feature before setting the content view and that's what I'm doing. Why is the error still there?

My Acitivty extends AppCompatActivity and is declared in manifest like this:

 <activity
            android:name=".activity.CameraActivity"
            android:label="@string/title_activity_camera"
            android:theme="@style/Theme.AppCompat.Light.Dialog"></activity>

EDIT full stack trace:

Process: irisrecognition.example.com.irisrecognition, PID: 29756
 java.lang.RuntimeException: Unable to start activity ComponentInfo{irisrecognition.example.com.irisrecognition/irisrecognition.example.com.irisrecognition.activity.CameraActivity}: android.util.AndroidRuntimeException: requestFeature() must be called before adding content
     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2693)
     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2758)
     at android.app.ActivityThread.access$900(ActivityThread.java:177)
     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1448)
     at android.os.Handler.dispatchMessage(Handler.java:102)
     at android.os.Looper.loop(Looper.java:145)
     at android.app.ActivityThread.main(ActivityThread.java:5942)
     at java.lang.reflect.Method.invoke(Native Method)
     at java.lang.reflect.Method.invoke(Method.java:372)
     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1400)
     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1195)
  Caused by: android.util.AndroidRuntimeException: requestFeature() must be called before adding content
     at com.android.internal.policy.impl.PhoneWindow.requestFeature(PhoneWindow.java:359)
     at android.app.Activity.requestWindowFeature(Activity.java:3785)
     at irisrecognition.example.com.irisrecognition.activity.CameraActivity.onCreate(CameraActivity.java:56)
     at android.app.Activity.performCreate(Activity.java:6289)
     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)
     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2646)
     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2758) 
     at android.app.ActivityThread.access$900(ActivityThread.java:177) 
     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1448) 
     at android.os.Handler.dispatchMessage(Handler.java:102) 
     at android.os.Looper.loop(Looper.java:145) 
     at android.app.ActivityThread.main(ActivityThread.java:5942) 
     at java.lang.reflect.Method.invoke(Native Method) 
     at java.lang.reflect.Method.invoke(Method.java:372) 
     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1400) 
     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1195) 
4ndro1d
  • 2,926
  • 7
  • 35
  • 65
  • put your error log here – Silvans Solanki Mar 28 '16 at 13:01
  • if you are extending appcompact activity then replace it with activity and check your code. – Silvans Solanki Mar 28 '16 at 13:08
  • i think this you need to read this url and it does have solution of your issue, http://android-developers.blogspot.in/2013/08/actionbarcompat-and-io-2013-app-source.html – Silvans Solanki Mar 28 '16 at 13:11
  • @SilvansSolanki yep, I replaced it and it's working now. Maybe you can create a proper answer with explanations – 4ndro1d Mar 28 '16 at 13:14
  • read the error carefully. It is written that requestFeature must be called before adding content and there are already answer to this question before. You should call it above super(); – Vivek Mishra Mar 28 '16 at 13:22
  • Please post manifest file and actvity class declaration. It may help to fix the issue. – sandeepmaaram Mar 28 '16 at 13:23
  • Possible duplicate of [requestWindowFeature(Window.FEATURE\_NO\_TITLE); causing the App to crash?](http://stackoverflow.com/questions/9737112/requestwindowfeaturewindow-feature-no-title-causing-the-app-to-crash) – Vivek Mishra Mar 28 '16 at 13:24
  • @VivekMishra calling before super doesn't help as I stated in other comments. No duplicate as well – 4ndro1d Mar 28 '16 at 13:30
  • your question is regarding crash and as you have stated in comments that crash doesn't occur on calling it before super therefore it is duplicate and if you have problem with title then you must have mentioned that in question – Vivek Mishra Mar 28 '16 at 13:33
  • and for title issue you must use theme that will be without action bar with your activity – Vivek Mishra Mar 28 '16 at 13:35
  • Sry, gonna fix it. It's same behaviour anyway – 4ndro1d Mar 28 '16 at 13:43
  • @VivekMishra changed the title – 4ndro1d Mar 28 '16 at 13:46
  • Possible duplicate of [How to hide app title in android?](http://stackoverflow.com/questions/2862528/how-to-hide-app-title-in-android) – Vucko Mar 28 '16 at 14:12

3 Answers3

0

You must call requestFeature before super.onCreate. it's necessary to call requestFeature() before super.onCreate() replace your code with

@Override
    protected void onCreate(Bundle savedInstanceState) {
        requestWindowFeature(Window.FEATURE_NO_TITLE);            
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
}
Chintan Desai
  • 2,607
  • 2
  • 22
  • 25
0

call requestWindowFeature before super.onCreate

@Override
    protected void onCreate(Bundle savedInstanceState) {
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
}
shobhan
  • 1,460
  • 2
  • 14
  • 28
0

you can try this:

<style name="Theme.AppCompat.Light.NoActionBar.FullScreen" parent="@style/Theme.AppCompat.Light">
    <item name="windowNoTitle">true</item>
    <item name="windowActionBar">false</item>
    <item name="android:windowFullscreen">true</item>
    <item name="android:windowContentOverlay">@null</item>
</style>

I hope this will help you.

rockstar
  • 587
  • 4
  • 22