Java "import java.util.Scanner" 不工作
Java "import java.util.Scanner" not working
我是第一次写代码,所以很抱歉让你捂脸
我想使用扫描仪 class 来读取用户输入。但是,我收到一个错误。当我遇到这个问题时我已经停止编码,因此代码还远未完成,但这是我所拥有的:
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();
}
}
那个returns这样的错误:
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.1\executor-snippets\run.xml:53: Java returned: 1
BUILD FAILED (total time: 0 seconds)
我在网上阅读了一些内容,得知扫描仪 class 仅在 java 1.5 及更高版本中受支持。但是,我应该有JDK 1.8。
我正在使用 NetBeans IDE 8.1.
如果有人能帮我解决这个问题,那就太好了。提前致谢!
编辑:我已经确保 "Project Properties" 中 "Sources" 下的 "Source/Binary Format" 设置为 JDK 8,但问题仍然存在。
尝试取消选中项目属性中的 "Compile on save" 设置(构建 -> 编译)
我是第一次写代码,所以很抱歉让你捂脸
我想使用扫描仪 class 来读取用户输入。但是,我收到一个错误。当我遇到这个问题时我已经停止编码,因此代码还远未完成,但这是我所拥有的:
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();
}
}
那个returns这样的错误:
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.1\executor-snippets\run.xml:53: Java returned: 1
BUILD FAILED (total time: 0 seconds)
我在网上阅读了一些内容,得知扫描仪 class 仅在 java 1.5 及更高版本中受支持。但是,我应该有JDK 1.8。 我正在使用 NetBeans IDE 8.1.
如果有人能帮我解决这个问题,那就太好了。提前致谢!
编辑:我已经确保 "Project Properties" 中 "Sources" 下的 "Source/Binary Format" 设置为 JDK 8,但问题仍然存在。
尝试取消选中项目属性中的 "Compile on save" 设置(构建 -> 编译)