Scanner is a Java class. All classes in Java should start with a capital letter.
Change
java.util.scanner;
to
java.util.Scanner;
Answer from David.Jones on Stack OverflowScanner is a Java class. All classes in Java should start with a capital letter.
Change
java.util.scanner;
to
java.util.Scanner;
either import the class or import the whole package
Importing class
import java.util.Scanner;
2.Importing the whole package
`import java.util.*;`
First will import only the selected class and the second will import all the classes in the package.
java - "Cannot be resolved to a type" when attempting to use Scanner - Stack Overflow
methods - Can't import java.util.Scanner - Stack Overflow
Can't import java.util.scanner, even though have downloaded new JDK
Scanner needs a capital S. Class names in Java are always capitalised.
More on reddit.comjava - "cannot find symbol - class Scanner" error - Stack Overflow
I tested if Java was running in command prompt and it said it was and i installed the extensions yet it still doesnt work, what am i doing wrong
You need to also import the class itself. At the very top of the file, above public class student, you need to add:
import java.util.Scanner;
In addition, I'd like to pose a few more possible corrections:
- Class names should be
PascalCase - Your code should have consistent indentation. Ctrl+Shift+F is your friend here.
Just use import java.util.Scanner; or use import java.util.*;
I guess you are using an IDE (like Netbeans or eclipse) which allows you to run the code even if certain classes are not compilable. During the application's runtime, if you access this class it would lead to this exception.
Solution :- Simply Clean Your Project and Build and Run Then Again.
Make sure you have configured PATH, CLASSPATH and JAVA_HOME variable in system Environment variable.
1) It might refers older version of java then 1.5
or
2) May be not added PATH,CLASSPATH, JAVA_HOME variable there.
BTW Your code is works fine in my Eclipse.
The problem is basically stated in the title. I've tried everything I could think of and what I have found in Google but nothing could resolve my problem. I'm currently running Java 11.02 on IntelliJ community edition (but have also tried with 11, no success though). The "java.util.scanner" isn't even underlined with a wavy red, but instead the word "scanner" is shown in red, the title is underlined though.
Does anyone know what I could try?
As the OP is a new beginner to programming, I would like to explain more.
You wil need this line on the top of your code in order to compile:
import java.util.Scanner;
This kind of import statement is very important. They tell the compile of which kind of Scanner you are about to use, because the Scanner here is undefined by anyone.
After a import statement, you can use the class Scanner directly and the compiler will know about it.
Also, you can do this without using the import statement, although I don't recommend:
java.util.Scanner scanner = new java.util.Scanner(System.in);
In this case, you just directly tell the compiler about which Scanner you mean to use.
You have to import java.util.Scanner at first line in the code.
import java.util.Scanner;
I'm trying to import the scanner class into my program (I'm using NetBeans) but when I type "import java.util.Scanner;" I get an error that says "cannot find symbol: class Scanner"
I thought maybe I typed it wrong so I even copy and pasted the line from code on a different working project and it's still saying that. Not sure where to go from here. Anyone know what could be causing this error?
So as the title suggests I am having issues declaring the scanner in Dr Java (I need to use this program for uni). Error states: 'scanner cannot he resolved to a type' code I've used is:
import java.util.Scanner; scanner sc = new scanner(system.in);
The errors are showing to the new scanner line specifically. I am running the latest, stable version of Dr java and have Googled the error extensively without much luck. Any advice would be appreciated.
Thanks.
The Scanner class is new in Java 5. I do not know what Hardy's default Java environment is, but it is not Sun's and therefore may be outdated.
I recommend installing the package sun-java6-jdk to get the most up-to-date version, then telling Eclipse to use it.
If you are using a version of Java before 1.5, java.util.Scanner doesn't exist.
Which version of the JDK is your Eclipse project set up to use?
Have a look at Project, Properties, Java Build Path -- look for the 'JRE System Library' entry, which should have a version number next to it.