android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application

HA HA HA !!!, You entrapped again in this error. Yes, if you are developing apps for a long time than definitely you faced this issue several times. If your answer is 'NO' than your developing skills are good or may be you didn't face it because you are a fresher. Or if answer is 'YES' than buddy, you forgot something in hurry. you know what is it ?

Error :

android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application.


Solution :

Somewhere in your alert dialog initialization. you passed context of your activity, replace it with [YourActivityName].this . That's it, your app will run perfectly after doing this. If still not working & same error occurs than ask problem in comment with detailed description. We will definitely help you to solve your issue.

Comments

  1. private void ShowPopup(){

    final Dialog dialog = new Dialog(mcontext, R.style.CustomDialog);
    Log.e("Dialog",""+dialog);
    // nestedScrollView.setBackgroundColor(Color.parseColor("#526565"));
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.setContentView(R.layout.contact_popup);
    dialog.setCanceledOnTouchOutside(false);
    dialog.getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT);
    dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
    contactmobile = dialog.findViewById(R.id.contact_mobile);
    contactname = dialog.findViewById(R.id.contact_name);
    ok = dialog.findViewById(R.id.ok);
    // email.setText(mPostData.get(contact.getId()).getEmail());
    // mobile.setText(mPostData.get(contact.getId()).getMobile());
    ok.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
    // Intent intent =new Intent(mcontext,LoginActivity.class);
    // mcontext.startActivity(intent);
    resend1();
    //dialog.dismiss();

    }
    });

    dialog.show();
    }

    ReplyDelete
  2. is not working this adapter class

    ReplyDelete
  3. Emperor Casino
    Play online casino games at Empire Casino | Try 1xbet for Real Money | No Download and No Registration | No Deposit Required | Join Now! | T&C's Apply! 인카지노 Rating: 3.9 · 제왕카지노 ‎3 votes · ‎Free · ‎Game

    ReplyDelete

Post a Comment