0

I have got this error and my application stops running

va.lang.NullPointerException: Attempt to invoke virtual method 'android.text.Editable android.widget.EditText.getText()' on a null object reference


when I click on the button next please tell me what to do instead in order to check that the fields are empty

  if ( ( lastName.getText().toString().matches("")) || ( firstName.getText().toString().matches("") ) ||
                    ( id.getText().toString().matches("") ) || ( email.getText().toString().matches("") ) ||
                            ( phoneNumber.getText().toString().matches("") ) )

Thank you for your help

ΦXocę 웃 Пepeúpa ツ
  • 43,054
  • 16
  • 58
  • 83
hannah
  • 3
  • 2
  • 1
    Please, post a [mvce](http://stackoverflow.com/help/mcve). – skypjack Nov 30 '15 at 22:14
  • one of your `EditText`s is `null` (`lastName` or `firstName` or ..) Check where you assign values to them for mistakes (usually something like `lastName = findById(R.id.something)`. – zapl Nov 30 '15 at 22:16

2 Answers2

0

with out more to go on, I would suspect that you're calling getText() on a null object so before you call getText() ensure the object references ar not null;

 if ( ( lastName == null || ( firstName == null ) ||
                ( id == null ) || ( email == null) ||
                        ( phoneNumber == null ) )
Ben Glasser
  • 2,761
  • 1
  • 21
  • 38
0

Use TextUtils.isEmpty(lastName.getText()) it is a better function which checks for null or empty strings.

feridok
  • 602
  • 5
  • 24