简体   繁体   English

用简单的英语,我如何使用图书馆?

[英]In plain english, How do I use a library?

I am trying to use Standard Library from Princeton, I used their downloader that automatically installs the library into Intellij, but when I try to use one of their functions, like StdOut.print() I get an error我正在尝试使用普林斯顿的标准库,我使用了他们的下载器,该下载器会自动将库安装到 Intellij 中,但是当我尝试使用他们的功能之一时,比如 StdOut.print() 我得到一个错误

This is the code:这是代码:

public class Main {
    public static void main(String[] args) {
    StdOut.print("Example");
    }
}

When trying to run this program I get the error message:尝试运行此程序时,我收到错误消息:

Error:(5, 9) java: cannot find symbol
  symbol:   variable StdOut
  location: class wsu.edu.Main

How do I make it so that I can use this library?我如何制作它以便我可以使用这个库?

I've heard a lot of confusing words trying to solve this issue, so please give it to me in plain English, assume I'm an idiot that knows nothing about JAR, class, classloader, classpath, package or default package. I've heard a lot of confusing words trying to solve this issue, so please give it to me in plain English, assume I'm an idiot that knows nothing about JAR, class, classloader, classpath, package or default package.

Is there something I can add to my code that will make this work?有什么我可以添加到我的代码中来使这项工作正常进行的吗?
Do I add a file to my folder?我是否将文件添加到我的文件夹? Can I also see an example?我也可以看一个例子吗?

Assuming you are using IntelliJ, open the project structure (icon on the top bar) in the Library section add the jar file.假设您使用的是 IntelliJ,请在 Library 部分打开项目结构(顶部栏上的图标),添加 jar 文件。 Now your IDE can use it.现在您的 IDE 可以使用它了。 Next, import it into your class using the import directive (above the class declaration).接下来,使用 import 指令(在 class 声明上方)将其导入 class。 Now you should be able to use it.现在你应该可以使用它了。

an example might be like this一个例子可能是这样的

import stdlib.StdIn;
public class Test
{
 public static final int Main(String[] args)
 {
    if(StdIn.hasNextChar())
    {
       //do something
    }
 }
 
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM