Java "import java.util.Scanner" not working

Vizor picture Vizor · Jun 11, 2016 · Viewed 16.5k times · Source

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.

Answer

thangdc94 picture thangdc94 · Jun 11, 2016

Try to uncheck "Compile on save" setting in the project properties (Build -> Compiling)