I just ran into a small null pointer problem. I was setting up an EditView
(textInputNewWeight)
for my Dialog Window. The code you see down here is a button with id - (confirmer)
, which checks the editView after clicking on it. It should make a toast message that the field is empty but it crashed every time when the editView is empty and I press the confirm button (code below).
Thanks for any help in advance
How should I write the first if statement to make it showing the toast message instead of crashing?
confirmer.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (textInputNewWeight == null){
Toast.makeText(getContext(), "This field cannot be empty.", Toast.LENGTH_SHORT).show();
}
}
});