Java“导入java.util.Scanner”不起作用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/37764278/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-03 02:46:29  来源:igfitidea点击:

Java "import java.util.Scanner" not working

javanetbeansjava.util.scannernetbeans-8.1

提问by Vizor

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:

我想使用 Scanner 类来读取用户输入。但是,我收到一个错误。当我遇到这个问题时,我已经停止编码,因此代码还远未完成,但这就是我所拥有的:

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.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 shouldhave JDK 1.8. I am using NetBeans IDE 8.1.

我在网上阅读了一些内容,并了解到 Scanner 类仅在 java 1.5 及更高版本中受支持。但是,我应该有 JDK 1.8。我使用的是 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.

编辑:我已经确保“项目属性”中“源”下的“源/二进制格式”设置为 JDK 8,但问题仍然存在。

回答by thangdc94

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

尝试取消选中项目属性中的“保存时编译”设置(构建 -> 编译)