怎样在Java中使用默认包中的类?

huangapple go评论79阅读模式
英文:

How does one use a class from a default package in Java?

问题

我正在学习一门名为《计算机科学:以实际应用为导向的编程》的课程。课程要求我们使用他们提供的 stdlib.jar 文件。我已按照说明将 .jar 文件添加到项目结构的依赖列表中。我正在使用 IntelliJ IDE。

当我使用 import StdOut 语句时,它显示类 'StdOut' 在默认包中。当我尝试使用 StdOut.printf("Hello World"); 时,出现了无法解析符号 'StdOut' 的错误。

我应该怎么做?

英文:

I am taking the course titled Computer Science: Programming with a purpose. The course instructs us to use the stdlib.jar that they have provided for the same. I have followed the instructions to add the .jar file to the list of dependencies in the project structure. I am using the IntelliJ IDE.

When I use the import StdOut statement, it says Class 'StdOut' is in the default package. When I try using StdOut.printf("Hello World");, I get the error that says Cannot resolve symbol 'StdOut'.

What should I do?

答案1

得分: 1

我认为这可能会有用。
https://stackoverflow.com/questions/2030148/whats-the-syntax-to-import-a-class-in-a-default-package-in-java

无论如何,如果我理解正确的话,你必须将它添加到Java路径中。

入门指南。要使用这个类,你的Java类路径中必须有StdOut.class。如果你使用了我们的自动安装程序,那么应该已经设置好了。否则,要么下载stdlib.jar并添加到你的Java类路径中,要么下载StdOut.java并将一个副本放在你的工作目录中。

英文:

I think this could be useful
https://stackoverflow.com/questions/2030148/whats-the-syntax-to-import-a-class-in-a-default-package-in-java

Anyway, if I got it correctly, you have to add it to the java path

Getting started. To use this class, you must have StdOut.class in your Java classpath. If you used our autoinstaller, you should be all set. Otherwise, either download stdlib.jar and add to your Java classpath or download StdOut.java and put a copy in your working directory.

huangapple
  • 本文由 发表于 2020年4月11日 00:20:42
  • 转载请务必保留本文链接:https://go.coder-hub.com/61144369.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定