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
- setContentView(R.layout.main);
- requestWindowFeature(Window.FEATURE_NO_TITLE);
解决方法如下:顺序换一下
[html] view plain copy
- requestWindowFeature(Window.FEATURE_NO_TITLE);
- setContentView(R.layout.main);