Chisx
Chisx

Reputation: 1986

Cannot resolve json import Intellij after adding dependency and library .jar

I cannot seem to resolve this issue after adding the json-lib-2.4-jdk15.jar from an online source to the project dependencies, screenshots provided to show walkthrough of what I am doing. (and yes I have repeatedly tried "Invalidate caches and restart")

The error: enter image description here

This is my Project Structure ("cmd + ;" or "File > Project Structure")

enter image description here It doesn't seem to work on "Scope" set to Compile either. Note that I added the .jar file as a library too because I'm just really unsure as to why I can't get this to work. Any help is greatly appreciated, thanks.

What do I seem to be doing incorrectly here?

Upvotes: 2

Views: 14844

Answers (1)

CrazyCoder
CrazyCoder

Reputation: 402065

The jar you have downloaded from https://sourceforge.net/projects/json-lib/ doesn't contain the classes you need. This jar contains net.sf.json package which is a different implementation of JSON Java library.

You are trying to use org.json.* classes which are provided by another library. The library you want to use is this one: JSON-java. At the bottom you can find the link to the Maven repository where you can get the jar file.

The latest version (at the moment of this reply) direct download link for the jar is here: json-20160810.jar.

Add it to the module dependencies and your problem should resolve.

Next time you observe similar issue browse inside the library jar under External Libraries node of IntelliJ IDEA project view and see what classes it contains and under which packages. This way you would know if the issue is caused by the wrong jar you've added to the dependencies and which doesn't actually contain the classes you want to use.

Upvotes: 5

Related Questions