英文:
importing things in java is causing cannot resolve error
问题
如何消除这个错误?这是我第一次使用Java。
答案1
得分: 1
你需要将想要使用的外部库添加到你的项目中。
要做到这一点,首先下载你想要使用的库的.jar
文件。你可以在mvnrepository.com或这个GitHub仓库中找到json
库的最新.jar
版本。
在IntelliJ中:
- 转到 File -> Project Structure
- 点击 Modules
- 点击 Dependencies 选项卡
- 点击
+
符号 - 选择 1 JARs or directories
- 选择刚刚下载的
.jar
文件 - 点击 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:
- Go to File -> Project Structure
- Click on Modules
- Click on Dependencies tab
- Click on
+
sign - Select 1 JARs or directories
- Select the
.jar
file you just downloaded - 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:
<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
答案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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论