Member Avatar

can u help me with this:

public static void main(String[] args) {
    Scanner s = new Scanner(System.in);
    String name;
    System.out.print("What is your name? ");
       if(name.equals("Bob")) {
     System.out.println("Oh hi, Bob. I know you. Good to see you again.");
    name = s.nextLine();
    }
}
}

what can i do?

Recommended Answers

Please post the full text of the error message that shows where the error happens.
Look at the source line where the error happens and see what variable has a null value and then backtrack in the code to see why that variable does not have a valid non-null value.

Jump to Post

All 2 Replies

You have to initialize your variable name,before you check it into if loop at line 5.
Also equals method is case sensitive, so it exactly matches what you have written into equals( "here" ).

So initialize it before checking.
put your line 7 before line 5.
and see.
i think its useful.

Also mark it solved if you get your answer.
thanks

Please post the full text of the error message that shows where the error happens.
Look at the source line where the error happens and see what variable has a null value and then backtrack in the code to see why that variable does not have a valid non-null value.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.