Netbeans中的StdIn库 - StdIn.readInt()

时间:2014-10-28 12:50:56

标签: java netbeans

我目前只是java的初学者,目前正在大学学习,但由于我不理解的原因,我不能问我的导师。

我在使用Netbeans中的StdIn库时遇到问题。在课堂上我们使用DrJava,但由于我不能让它在我的Mac上运行,我已经使用了Netbeans。在下面的代码中,我可以让它在Java博士中运行(它是使用标准输入和输出的基本介绍),但是当我在netbeans中运行它时,它会引发运行时错误。

(我已将StdIn.java和StdOut.java文件包含在与MaxMin.java文件相同的目录中)

    public class MaxMin {


public static void main(String[] args) {

    // first value read initialized min and max
    int max = StdIn.readInt();
    int min = max;

    // read in the data, keep track of min and max
    while (!StdIn.isEmpty()) {
        int value = StdIn.readInt();
        if (value > max) max = value;
        if (value < min) min = value;
    }

    // output
    StdOut.println("maximum  = " + max + ", minimum = " + min);
}

然后我在netbeans输出窗口中收到此运行时错误。

    Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - Erroneous sym type: maxmin.StdIn.readInt
at maxmin.MaxMin.main(MaxMin.java:19)
    Java Result: 1
    BUILD SUCCESSFUL (total time: 0 seconds)

我为一个非常基本的问题道歉,但我在堆栈溢出中找不到任何相关的帮助。

我确信代码本身没问题,因为它完全是从在线教科书中复制的:

http://introcs.cs.princeton.edu/java/15inout/MaxMin.java.html

有人可以解释为什么Netbeans会抛出运行时错误而不是要求我输入吗?

EDIT 在回应一个建议时,我在项目构建选项中取消选择“在保存时编译”,然后执行“清理和构建项目”。并提出了这些错误:

ant -f /Users/xUsernamex/NetBeansProjects/MaxMin -Dnb.internal.action.name=rebuild clean jar
init:
deps-clean:
Updating property file: /Users/xUsernamex/NetBeansProjects/MaxMin/build/built-clean.properties
Deleting directory /Users/xUsernamex/NetBeansProjects/MaxMin/build
clean:
init:
deps-jar:
Created dir: /Users/xUsernamex/NetBeansProjects/MaxMin/build
Updating property file: /Users/xUsernamex/NetBeansProjects/MaxMin/build/built-jar.properties
Created dir: /Users/xUsernamex/NetBeansProjects/MaxMin/build/classes
Created dir: /Users/xUsernamex/NetBeansProjects/MaxMin/build/empty
Created dir: /Users/xUsernamex/NetBeansProjects/MaxMin/build/generated-sources/ap-source-output
Compiling 3 source files to /Users/xUsernamex/NetBeansProjects/MaxMin/build/classes
/Users/xUsernamex/NetBeansProjects/MaxMin/src/maxmin/MaxMin.java:19: error: cannot find symbol
    int max = StdIn.readInt();
  symbol:   variable StdIn
  location: class MaxMin
/Users/xUsernamex/NetBeansProjects/MaxMin/src/maxmin/MaxMin.java:23: error: cannot find symbol
    while (!StdIn.isEmpty()) {
  symbol:   variable StdIn
  location: class MaxMin
/Users/xUsernamex/NetBeansProjects/MaxMin/src/maxmin/MaxMin.java:24: error: cannot find symbol
        int value = StdIn.readInt();
  symbol:   variable StdIn
  location: class MaxMin
/Users/xUsernamex/NetBeansProjects/MaxMin/src/maxmin/MaxMin.java:31: error: cannot find symbol
            if (value < 0) StdOut.println("Please use positive values");
  symbol:   variable StdOut
  location: class MaxMin
/Users/xUsernamex/NetBeansProjects/MaxMin/src/maxmin/MaxMin.java:35: error: cannot find symbol
    StdOut.println("maximum  = " + max + ", minimum = " + min);
  symbol:   variable StdOut
  location: class MaxMin
5 errors
/Users/xUsernamex/NetBeansProjects/MaxMin/nbproject/build-impl.xml:923: The following error         occurred while executing this line:
/Users/xUsernamex/NetBeansProjects/MaxMin/nbproject/build-impl.xml:263: Compile failed; see the     compiler error output for details.
BUILD FAILED (total time: 0 seconds)

在我看来,好像我在识别StdIn和StdOut库时遇到了一些问题,但我不知道该怎么做。在Netbeans中,我应该将它们放在哪个文件夹中?

1 个答案:

答案 0 :(得分:1)

如果某些类不可编译,则会在netbeans中发生此错误。您可以尝试取消选择&#39; Compile On Save&#39;在项目构建选项中。现在清理并构建项目,然后运行代码。