@Override
protected Dialog onCreateDialog(int id) {
Dialog dialog = null;
switch(id) {
case DIALOG_ID:
LayoutInflater inflater = getLayoutInflater();
View InfoLayout = inflater.inflate(R.layout.info_dialog, null);
AlertDialog.Builder b = new AlertDialog.Builder(MyActivity.this)
.setView(InfoLayout );
initInfoDialog(dialog);
return dialog;
...
private void initInfoDialog(Dialog dialog) {
//this line has the null pointer
WindowManager.LayoutParams lp = dialog.getWindow().getAttributes();
Why is dialog.getWindow() returning null in this case?
I faced the same problem and I see now the getWindow() documentation is actually telling why (not the reason but why at this specific point). You can retrieve the window after calling show().