Android – error: requestfeature() must be called before adding content and is still invalid
I know I've asked similar questions in the past, but even with these suggestions, I can't seem to do it
I got the above abnormal termination in the "show()" command
public void onCreate(Bundle savedInstanceState) {
try{
super.onCreate(savedInstanceState);
setContentView(R.layout.submitscoredummylayout);
scoreloopInit();
AlertDialog whatToUploadDialog;
whatToUploadDialog = new AlertDialog.Builder(YanivSubmitscoreActivity.this).create();
whatToUploadDialog.setContentView(R.layout.submitscoreprompt);
whatToUploadDialog.setTitle(R.string.uploadedscoreTitle);
whatToUploadDialog.setCancelable(false);
((Check@R_103_2419@)whatToUploadDialog.findViewById(R.id.ckbscoreloop)).setChecked(settings.getUploadToSL());
((Check@R_103_2419@)whatToUploadDialog.findViewById(R.id.ckbFacebook)).setChecked(settings.getUploadToFB());
((Check@R_103_2419@) whatToUploadDialog.findViewById(R.id.ckbscoreloop)).setOnCheckedchangelistener(new OnCheckedchangelistener() {
@Override
public void onCheckedChanged(CompoundButton ck@R_103_2419@, boolean isChecked) {
settings.setUploadToSL(isChecked,true);
findViewById(R.id.btnYes).setEnabled(isChecked||settings.getUploadToFB());
}
});
((Check@R_103_2419@) whatToUploadDialog.findViewById(R.id.ckbFacebook)).setOnCheckedchangelistener(new OnCheckedchangelistener() {
@Override
public void onCheckedChanged(CompoundButton ck@R_103_2419@, boolean isChecked) {
settings.setUploadToFB(isChecked,true);
findViewById(R.id.btnYes).setEnabled(isChecked||settings.getUploadToSL());
}
});
whatToUploadDialog.findViewById(R.id.btnYes).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
submitscore(SUBMIT_UPLOAD_TO_SL);
whatToUploadDialog.dismiss();
}
});
whatToUploadDialog.findViewById(R.id.btnNo).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
whatToUploadDialog.dismiss();
finish();
}
});
whatToUploadDialog.show();
}
Of logcat:
W/System.err(14969): android.util.AndroidRuntimeException: requestFeature() must be called before adding content
W/System.err(14969): at com.android.internal.policy.impl.PhoneWindow.requestFeature(PhoneWindow.java:184)
W/System.err(14969): at com.android.internal.app.AlertController.installContent(AlertController.java:198)
W/System.err(14969): at android.app.AlertDialog.onCreate(AlertDialog.java:251)
W/System.err(14969): at android.app.Dialog.dispatchOnCreate(Dialog.java:307)
W/System.err(14969): at android.app.Dialog.show(Dialog.java:225)
W/System.err(14969): at ui.YanivSubmitscoreActivity.onCreate(YanivSubmitscoreActivity.java:105)
W/System.err(14969): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
W/System.err(14969): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
W/System.err(14969): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
W/System.err(14969): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
W/System.err(14969): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
W/System.err(14969): at android.os.Handler.dispatchMessage(Handler.java:99)
W/System.err(14969): at android.os.Looper.loop(Looper.java:123)
W/System.err(14969): at android.app.ActivityThread.main(ActivityThread.java:4627)
W/System.err(14969): at java.lang.reflect.Method.invokeNative(Native Method)
W/System.err(14969): at java.lang.reflect.Method.invoke(Method.java:521)
W/System.err(14969): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:871)
W/System.err(14969): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:629)
W/System.err(14969): at dalvik.system.NativeStart.main(Native Method)
resolvent:
I encountered the same problem. I found that the problem occurred only when I performed the following two operations:
>I don't use the Activity Management dialog box (activity. Showdialog() – > activity. Oncreatedialog() / onprepareddialog()) > I did dialog. Findviewbyid() (this is really between successful row differences or requestfeature exceptions!)
final Builder dialogBuilder = new AlertDialog.Builder(activity);
b.setView(rootView);
b.setIcon(android.R.drawable.ic_dialog_info);
b.setTitle(R.string.message_of_the_day_title);
b.setCancelable(false);
dialog = b.createDialog();
dialog.findViewById(R.id.myid); // this is the problem
Dialog. Findviewbyid() caused a problem because it called
dialog.getWindow().getDecorView()
And getdecorview(), Javadoc says:
Not very good. Findviewbyid() has side effects, causing the seemingly correct application to crash. Why is there a difference between the activity managed dialog box and the ordinary dialog box I don't know, but I guess getdecorview() does some magic for the activity managed dialog box
I did this because I used the activity managed dialog to handle the dialog
For me, the solution is to use rootview. Findviewbyid() to manipulate rootview, not dialog box