Netbeans 中的 StdIn 库 - StdIn.readInt() [英] StdIn library in Netbeans - StdIn.readInt()

查看:55
本文介绍了Netbeans 中的 StdIn 库 - StdIn.readInt()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是一个java初学者,目前在大学学习,但由于原因我不会进入我不能问我的导师.

I'm only a beginner with java currently studying at university, but for reasons i'll not go into I can't ask my tutor.

我在 Netbeans 中使用 StdIn 库时遇到问题.在课堂上,我们使用 DrJava,但由于我无法在 Mac 上运行它,因此我求助于 Netbeans.在下面的代码中,我可以让它在 Dr Java 中运行(这是使用标准输入和输出的基本介绍),但是当我在 netbeans 中运行它时,它会引发运行时错误.

I'm having a problem using the StdIn library in Netbeans. In classes we use DrJava but since I can't get it to run on my Mac, i've resorted to Netbeans. In the following code, I can get it to run in Dr Java (it is a basic introduction to using standard input and output), but when i run it in netbeans, it throws a runtime error.

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

(i have included the StdIn.java and StdOut.java files in the same directory as the MaxMin.java file)

    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 输出窗口中收到此运行时错误.

I then get this runtime error in the netbeans output window.

    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)

对于必须是非常基本的问题,我深表歉意,但我在堆栈溢出中找不到任何相关帮助.

I apologise for what must be a very basic problem, but i can't find any relevant help on this here in stack overflow.

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

I'm sure the code itself is ok as it is copied exactly from an online textbook:

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

谁能解释一下为什么 Netbeans 抛出运行时错误而不是要求我输入?

Can anyone shed some light on why Netbeans throws the runtime error instead of asking me for input?

编辑作为对建议的回应,我在项目构建选项中取消选择了保存时编译",然后执行了清理并构建项目".并提出了这些错误:

EDIT In response to a suggestion, I deselected 'Compile on save' in the project build options and then did the 'clean and build project'. and came up with these errors:

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 中,我应该将它们放在哪个文件夹中?

It looks to me as if I'm having some issue with recognising the StdIn and StdOut libraries, but I'm not sure what to do about that. In Netbeans, which folder should I put them in?

推荐答案

如果某些类不可编译,则会在 netbeans 中发生此错误.您可以尝试在项目构建选项中取消选择保存时编译".现在清理并构建您的项目,然后运行您的代码.

This error occurs in netbeans if some classes are not compilable. you can try deselecting 'Compile On Save' in the project build options. Now clean&build your project and then run your code.

这篇关于Netbeans 中的 StdIn 库 - StdIn.readInt()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆