user1213032
user1213032

Reputation: 1

Scanner error Symbol not found

I have imported the java class but i keep getting this error with the following code

Error: C:\Users\xiangzheng\Desktop\passoff\P70.java:51: error: cannot find symbol String a = scanner.next;

Code:

Scanner scanner = new Scanner(sentence);
        scanner.useDelimiter(" ");
        String a = scanner.next;

Upvotes: 0

Views: 553

Answers (3)

Blaine
Blaine

Reputation: 33

I believe next is a method, not a variable.

Try this and let me know if it works.

String a = scanner.next();

Upvotes: 2

Shashank Kadne
Shashank Kadne

Reputation: 8101

Change scanner.next to scanner.next()

Upvotes: 2

Jack
Jack

Reputation: 133587

Probably you are just missing the parenthesis from the method invokation, try with

String a = scanner.next();

scanner.next tries to access to an instance variable which doesn't exist for Scanner class.

Upvotes: 6

Related Questions