This is my current code which is inside a javatogo
package and a class file named Console.java
.
package javatogo;
import java.util.Scanner;
public class Console {
/**
* Private static Scanner for multiple use.
*/
// update: I did have System.in - I just did not copy and paste
// the code directly from my project since it has things not needed
private static Scanner scanner = new Scanner(System.in);
/**
* Static method to return a user input.
*
* @param line
* @return String
*/
public static String readLine(
String line
) {
System.out.print(line);
return scanner.nextLine();
}
}
I found the documentation to read a console input which uses the java.util
package and the Scanner.java
however when I hit CTRL+SHIFT+O
to automatically import or manually import it, I get an error on the import and instance:
Scanner cannot be resolved to a type
The import java.util.Scanner cannot be resolved
Any help would be appreciated, I have refreshed Eclipse and restarted it - I am still receiving this error.
Note: When I change the import to import java.util.*
I receive no further errors on the import but the Scanner
instance still errors.
Update: I took a print screen if it helps anyone.
Resolved because I updated my Java, I had to manually tell Eclipse my JDK path.
Thanks to @Pshemo for the answer and everyone who helped.