Wednesday, 2 September 2015

android customized AlertDialog, findViewById, java.lang.NullPointerException




If you customized a AlertDialog (with a layout file), you may get "NullPointerException" when you try to get element by "findViewById":

loginWindow.findViewById(R.id.login_error_message);

That because you try to get the element before the page is ready.

Solution:

Do that after:

loginWindow.show();








explanation:

Same as activity, you can't do the same call before "setContentView(R.layout.activity_info);"

No comments:

Post a comment