Java "import java.util.Scanner" not working
17,473
Try to uncheck "Compile on save" setting in the project properties (Build -> Compiling)
Author by
Vizor
Updated on June 04, 2022Comments
-
Vizor about 2 years
This is my first time coding, so I'm sorry if I caused you to facepalm.
I wanted to use the Scanner class to read the user input. However, I get an error. I've stopped coding when I faced this problem, thus the code is far from done, but this is what I have:
package trigger; import java.util.Scanner; public class Trigger { public static void main(String[] args) { System.out.println("Please input known values"); Scanner input = new Scanner(System.in); System.out.println("Angle A"); String Ain = input.next(); System.out.println("Angle B"); String Bin = input.next(); System.out.println("Angle C"); String Cin = input.next(); System.out.println("Side A"); String ain = input.next(); System.out.println("Side B"); String bin = input.next(); System.out.println("Side C"); String cin = input.next(); } }
That returns a error like this:
java.lang.ExceptionInInitializerError Caused by: java.lang.RuntimeException: Uncompilable source code - cannot find symbol symbol: class Scanner location: class java.util at trigger.Trigger.<clinit>(Trigger.java:2) Exception in thread "main" C:\Users\******\AppData\Local\NetBeans\Cache\8.1\executor-snippets\run.xml:53: Java returned: 1 BUILD FAILED (total time: 0 seconds)
I've read some things online, and learned that the Scanner class is only supported in java 1.5 and up. However, I should have JDK 1.8. I am using NetBeans IDE 8.1.
If anyone can help me with this, that will be amazing. Thanks in advance!
EDIT: I've made sure the "Source/Binary Format" under "Sources" in "Project Properties" is set to JDK 8, yet the problem persists.
-
Vizor about 8 yearsThanks! That allowed it to run. I will see if it is working..(I still have the "cannot find symbol" error message at the side)