0

I HAVE 2 QUESTIONS. First of all, I know these type of questions have been asked a lot but I do not seem to understand what I have to change. I have this following code and the line of code where I have 'if(contactnumber.isEmpty())' is giving me an error saying 'int cannot be dereferenced'.

Secondly, my other problem is when I try to run this program and press a button in order to make this program work nothing happens, meaning that if the text fields are empty none of the validations come. Any suggestions on what I have to do?

    namevalidation.setText(""); //Set text for the label
    surnamevalidation.setText(""); //Set text for the label
    contactvalidation.setText(""); //Set text for the label

    String name = namefield.getText(); //Get text form a textfield
    String surname = surnamefield.getText(); //Get text form a textfield
    int contactnumber = Integer.parseInt(contactfield.getText()); //Getting the numeric value form the textfield


    boolean passed=true;

    if(name.isEmpty())//Checking if the name or surname is empty
    {
        namevalidation.setText("Please enter your name!");
        passed = false;
    }

    if(surname.isEmpty())
    {
        surnamefield.setText("Please enter your surname!");
        passed = false;
    }
    if(contactnumber.isEmpty())//THIS IS GIVING ME THE ERROR
    {
        contactfield.setText("Please enter your number!");
        passed = false;
    }
Z.Mizzi
  • 11
  • 2
  • `contactNumber` is an int. Why are you trying to check if it's empty? Did you mean to check `contactfield.getText().isEmpty()`? If so wait to parse until after you have verified – GBlodgett Jan 09 '19 at 21:43
  • Instead of checking `contactNumber`, which is an integer, you should check `contactfield.getText().isEmpty()` before parsing it to an integer. – forpas Jan 09 '19 at 21:46
  • Do you think you can help me with the other problem ? – Z.Mizzi Jan 09 '19 at 21:53
  • Don't copy and paste any code that you did not try to understand. Please try to debug as well. – FullStackDeveloper Jan 09 '19 at 21:54

0 Answers0