requestFeature() must be called before adding content产生原因和解决办法

03-24 01:07:31.504 2957-2957/com.santai.jrj E/AndroidRuntime: FATAL EXCEPTION: main

Process: com.santai.jrj, PID: 2957

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

at com.android.internal.policy.impl.PhoneWindow.requestFeature(PhoneWindow.java:249)

at com.android.internal.app.AlertController.installContent(AlertController.java:234)

at android.app.AlertDialog.onCreate(AlertDialog.java:337)

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

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

[html] view plain copy
  1. setContentView(R.layout.main);
  2. requestWindowFeature(Window.FEATURE_NO_TITLE);

解决方法如下:顺序换一下

[html] view plain copy
  1. requestWindowFeature(Window.FEATURE_NO_TITLE);
  2. setContentView(R.layout.main);
上一篇:android.util.AndroidRuntimeException: requestFeature() must be called before adding content解决办法


下一篇:January 14th, 2018 Week 02nd Sunday