Error in an if statement : int cannot be deferenced and validation program not working when running

时间:2019-01-09 21:43:01

标签: java netbeans

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;
    }

0 个答案:

没有答案