requestFeature() must be called before adding content

11-06 07:09:07.638  24338-24338/? E/AndroidRuntime﹕ FATAL EXCEPTION: main
    java.lang.RuntimeException: Unable to start activity ComponentInfo{jukay.com.myapplication/jukay.com.myapplication.MainActivity}: android.util.AndroidRuntimeException: requestFeature() must be called before adding content
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2233)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2283)
            at android.app.ActivityThread.access$600(ActivityThread.java:147)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1262)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:137)
            at android.app.ActivityThread.main(ActivityThread.java:5160)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:525)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
            at dalvik.system.NativeStart.main(Native Method)
     Caused by: android.util.AndroidRuntimeException: requestFeature() must be called before adding content
            at com.android.internal.policy.impl.PhoneWindow.requestFeature(PhoneWindow.java:227)
            at android.app.Activity.requestWindowFeature(Activity.java:3264)
            at jukay.com.myapplication.MainActivity.onCreate(MainActivity.java:19)
            at android.app.Activity.performCreate(Activity.java:5133)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2197)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2283)
            at android.app.ActivityThread.access$600(ActivityThread.java:147)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1262)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:137)
            at android.app.ActivityThread.main(ActivityThread.java:5160)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:525)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
            at dalvik.system.NativeStart.main(Native Method)

  出现这样的错误,网上大多数说是下面的代码写反了

requestWindowFeature(Window.FEATURE_NO_TITLE);// 隐藏了标题栏

        setContentView(R.layout.activity_main);

事实上代码没有写反的时候也有可能出现这样的问题,

如果是继承Activity就没有问题

时间: 2024-10-26 18:15:31

requestFeature() must be called before adding content的相关文章

Android开发中遇到的requestFeature() must be called before adding content异常

缘起 上一篇博文中讲到了几种实现全屏显示Activity内容的方法.然而实际在实现中发现了一些问题,在本篇博文中进行总结下.首先交代一下开发环境,本人使用的是Android Studio 1.5.1,因此使用Eclipse ADT开发或者低版本的SDK的时候可能不会碰到这个问题.首先看onCreate()方法中的实现代码: 1 @Override 2 protected void onCreate(Bundle savedInstanceState) { 3 super.onCreate(sav

requestFeature() must be called before adding content错误

05-14 22:16:42.808: E/AndroidRuntime(22906): FATAL EXCEPTION: main05-14 22:16:42.808: E/AndroidRuntime(22906): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.sensor_125/com.example.sensor_125.MainActivity}: android.uti

android.util.AndroidRuntimeException: requestFeature() must be called before adding content解决办法

最近在学习第一行代码这本书,里面的关于activity生命周期有一段例子,但是我自己用mac上装的as运行一直出问题,看log的话就是android.util.AndroidRuntimeException: requestFeature() must be called before adding content这个错误,从网上找了半天,终于找到了解决办法,虽然没有太明白原理,但是在这里做个分享吧. 这个是修改之后的代码 1 protected void onCreate(Bundle sav

关于requestFeature() must be called before adding content

想显示dialog时,如果想显示的是自定义布局的dialog,并使用如下方式,则会报错requestFeature() must be called before adding content AlertDialog dlg = new AlertDialog.Builder(this).create(); dlg.setContentView(R.layout.dialog_layout); dlg.show(); 修改方法是,改变一下顺序,先dlg.show();然后再进行setConten

requestFeature() must be called before adding content 解决方法

今天在做一个app引导界面的时候,想设置成全屏显示,一直报错aused by: android.util.AndroidRuntimeException: requestFeature() must be called before adding content,百度了很多都不行后来实在没办法了,Google了一下,终于解决了,由于我用的是Google最新的开发工具,继承的是ActionBarActivity,改成继承Activity 完美解决!! //supportRequestWindowF

[Android]requestFeature() must be called before adding content

public void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); view = new MainView(getBaseContext()); SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this

Android Exception 9(requestFeature() must be called before adding content)

08-05 17:36:12.799: W/System.err(10378): java.lang.reflect.InvocationTargetException08-05 17:36:12.799: W/System.err(10378):     at java.lang.reflect.Method.invokeNative(Native Method)08-05 17:36:12.809: W/System.err(10378):     at java.lang.reflect.

Android showDialog时报错requestFeature() must be called before adding content

View view = View.inflate(this, R.layout.layout_dialog, null); AlertDialog alertDialog = new AlertDialog.Builder(TabActivity.this, R.style.CustomDialog).create(); alertDialog.setContentView(view); alertDialog.show(); alertDialog.setCanceledOnTouchOuts

(七十四)Android showDialog时报错requestFeature() must be called before adding content

出现此问题是由于dialog.show()之前调用了dialog.setContentView()或者dialog.getwindow()等,正确的应该是dialog.show()之后调用dialog.setContentView()或者dialog.getwindow()