Skip to content Skip to sidebar Skip to footer

Findviewbyid From Alertdialog (with Custom Layout) - Nullpointerexception

I’m trying to get the text out of EditTexts within an AlertDialog, which is created as you can see below. The problem is, that I can’t retrieve the textviews. All I get is a nu

Solution 1:

You need to search inside of the View that you inflate for your Alert dialog, say that the view you inflate is as follows:

Viewview= inflater.inflate(R.layout.dialog_add_player, container);

then you would need to do

EditTexteditFirstName= (EditText) view.findViewById(R.id.editFirstName);
EditTexteditLastName= (EditText) view.findViewById(R.id.editLastName);

It looks like right now you are trying to instantiate a variable for something that does not exist, you have no reference of where the EditText is actually located, it's trying to look inside of the current view, which does not contain the EditText.

Post a Comment for "Findviewbyid From Alertdialog (with Custom Layout) - Nullpointerexception"