FATAL EXCEPTION: main
Process: com.kingchannels.cabp, PID: 22995
android.util.AndroidRuntimeException: requestFeature() must be called before adding content
at com.android.internal.policy.impl.PhoneWindow.requestFeature(PhoneWindow.java:302)
at com.android.internal.app.AlertController.installContent(AlertController.java:233)
at android.app.AlertDialog.onCreate(AlertDialog.java:356)
at android.app.Dialog.dispatchOnCreate(Dialog.java:373)
at android.app.Dialog.show(Dialog.java:274)
at com.kingchannels.cabp.ui.user.dialog.EducationaBackDialog.show(EducationaBackDialog.java:52)
at com.kingchannels.cabp.ui.user.UserInformationActivity.showEductionOrBack(UserInformationActivity.java:464)
at com.kingchannels.cabp.ui.user.UserInformationActivity.onClick(UserInformationActivity.java:449)
at android.view.View.performClick(View.java:4784)
at android.view.View$PerformClick.run(View.java:19890)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
出现此问题是由于dialog.show()之前调用了dialog.setContentView()或者dialog.getwindow()等,正确的应该是dialog.show()之后调用dialog.setContentView()
Caused by: Android.util.AndroidRuntimeException: requestFeature() must be called before adding content
- setContentView(R.layout.main);
- requestWindowFeature(Window.FEATURE_NO_TITLE);
解决方法如下:顺序换一下
- requestWindowFeature(Window.FEATURE_NO_TITLE);
-
- setContentView(R.layout.main);