2

I am trying to write a program in Java using Maven in IntelliJ which calls an API using HttpURLConnection and parses the response using JSONArray and JSONObject. I have attempted to import the org.json JAR file, and I've updated my pom.xml to include it as a dependency, but I'm still getting the following error.

Test.java:1: error: package org.json does not exist import org.json.JSONArray; 

pom.xml:

<dependency> <groupId>org.json</groupId> <artifactId>json</artifactId> <version>20210307</version> </dependency> 

I have also tried adding the downloaded JAR file to Project Structure > Modules > Dependencies but have had no luck. Is there something else I could be overlooking here?

1

2 Answers 2

3

Your dependency and import looks correct. Reloading all maven dependencies should resolve the issue. Check this post out: Force Intellij IDEA to reread all maven dependencies

Sign up to request clarification or add additional context in comments.

Comments

0

I had the same problem, added org.json dependency and reloaded maven, But still Intellij didn't recognize it. I tried write following code in module-info.java , then Intellij recognized it:

requires org.json;

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.