关于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();然后再进行setContentView(R.layout.dialog_layout);就没问题了。

时间: 2024-10-07 06:09:28

关于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 解决方法

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

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: requestFe

[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()