在Java中导入东西会导致”cannot resolve error”错误。

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

importing things in java is causing cannot resolve error

问题

如何消除这个错误?这是我第一次使用Java。

英文:

在Java中导入东西会导致”cannot resolve error”错误。

在Java中导入东西会导致”cannot resolve error”错误。

How to get rid of this error? It's my first time using Java

答案1

得分: 1

你需要将想要使用的外部库添加到你的项目中。

要做到这一点,首先下载你想要使用的库的.jar文件。你可以在mvnrepository.com这个GitHub仓库中找到json库的最新.jar版本。

在IntelliJ中:

  1. 转到 File -> Project Structure
  2. 点击 Modules
  3. 点击 Dependencies 选项卡
  4. 点击 + 符号
  5. 选择 1 JARs or directories
  6. 选择刚刚下载的.jar文件
  7. 点击 Apply

现在你可以在项目中使用import org.json.JSONArray;import org.json.JSONObject;,不会出现错误。

注意: 你应该真的使用一些依赖管理工具,比如像其他人已经建议的Maven

英文:

You need to add the external library that you want to use to your project.

To do that, first download the .jar file of the library that you want to use. You can find the latest .jar release of the json library at mvnrepository.com or on this github repository.

In IntelliJ:

  1. Go to File -> Project Structure
  2. Click on Modules
  3. Click on Dependencies tab
  4. Click on + sign
  5. Select 1 JARs or directories
  6. Select the .jar file you just downloaded
  7. Click Apply

Now you can import org.json.JSONArray; or import org.json.JSONObject; in your project without an error.

Note: you should really use some type of dependency management tool like for example Maven like others already suggested.

答案2

得分: 0

Right click the project, add framework support, add maven, and inside the pom.xml file that maven created, add the following code:

<dependencies>
    <dependency>
        <groupId>org.json</groupId>
        <artifactId>json</artifactId>
        <version>20200518</version>
    </dependency>
</dependencies>

Then click the little refresh button inside the maven tab on the right of the screen.

Now you should be able to use the json library. This is how you use external libraries using maven, it's way faster than importing external jar's manually.

Hope it helps, if you have any other question just leave a comment.

英文:

Right click the project, add framework support, add maven, and inside the pom.xml file that maven created, add the following code:

&lt;dependencies&gt;
&lt;dependency&gt;
    &lt;groupId&gt;org.json&lt;/groupId&gt;
    &lt;artifactId&gt;json&lt;/artifactId&gt;
    &lt;version&gt;20200518&lt;/version&gt;
&lt;/dependency&gt;
&lt;/dependencies&gt;

Then click the little refresh button inside the maven tab on the right of the screen.
在Java中导入东西会导致”cannot resolve error”错误。

Now you should be able to use the json library. This is how you use external libraries using maven, it's way faster than importing external jar's manually.

Hope it helps, if you have any other question just leave a comment

答案3

得分: 0

问题是你不能导入这些包,因为你没有它们。为了解决这个问题,你需要外部添加一个包含这些包的Jar文件。尝试使用项目管理工具,比如Maven(通常用于依赖管理),或者尝试手动添加缺失的Jar文件,通过从互联网上下载或从Maven中央仓库下载。

英文:

Problem is you can't import those packages because you don't have them with you.To solve this you need add a Jar file externally which contains those packages.
Try using a project management tool like Maven[Commonly use for dependency management] or try to add that missing Jar files manually by downloading them through the internet or through the maven central repository.

huangapple
  • 本文由 发表于 2020年7月29日 22:03:10
  • 转载请务必保留本文链接:https://go.coder-hub.com/63155441.html
匿名

发表评论

匿名网友

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

确定