In my case i was using maven build tool and got this error so had to add below dependency from here like below and error resolved.
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20180130</version>
</dependency>
Answer from Alien on Stack OverflowI have been trying to figure out this issue forever now but I can't seem to see what I'm doing wrong. I am using VSCode and added the json library (json-20220329.jar) to my referenced libraries. When I add the jar file the errors in my main file go away regarding JSONObject and JSONArray. Everything looks fine until I try running the code and it says that the "package org.json does not exist." I was wondering if anyone knew what could be the problem.
CODE: (App.java)
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import org.json.JSONObject;
import org.json.JSONArray;
public class App {
public static void main(String[] args) {
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder().uri(URI.create("https://jsonplaceholder.typicode.com/albums")).build();
client.sendAsync(request, HttpResponse.BodyHandlers.ofString())
.thenApply(HttpResponse::body)
.thenAccept(System.out::println)
.join();
}
public static String parse(String responseBody) {
JSONArray albums = new JSONArray(responseBody);
for (int i = 0; i < albums.length(); i++)
{
JSONObject album = albums.getJSONObject(i);
int id = album.getInt("id");
int userID = album.getInt("userId");
String title = album.getString("title");
System.out.println(id + "\t" + title + "\t" + userID);
}
return null;
}
}ERROR:
App.java:8: error: package org.json does not exist
import org.json.JSONObject;
^
App.java:9: error: package org.json does not exist
import org.json.JSONArray;
^
App.java:26: error: cannot find symbol
JSONArray albums = new JSONArray(responseBody);
^
symbol: class JSONArray
location: class App
App.java:26: error: cannot find symbol
JSONArray albums = new JSONArray(responseBody);
^
symbol: class JSONArray
location: class App
App.java:29: error: cannot find symbol
JSONObject album = albums.getJSONObject(i);
^
symbol: class JSONObject
location: class App
5 errorspackage does not exist
java - org.json cannot be resolved to a module? - Stack Overflow
Can't import "json-20240303" library into my project.
error: package org.json does not exist
In my case i was using maven build tool and got this error so had to add below dependency from here like below and error resolved.
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20180130</version>
</dependency>
Class org.json.JSONObject is available in json-20131018.jar. You need to download this jar and add this jar to your buildpath.
In order to add external jar to buildpath you can - right click on your project in eclipse - click build path -> configure build path - goto tab libraries - there you will find to add external JAR
This will allow you to include any external jar into your build path.
I'm going to start by saying I'm a complete novice in Java. I've started computer science recently and I've got a project where I have to create a project to represent a server using sockets. The server will has to function as a control a library's book record/register. My professor provided a .json file with the book lists which I have to use.
I tried creating the project on VS Code, but after following these steps:
Downloaded the library from the Maven Repository.
Created a lib folder in your project's root directory and move the json-20230303.jar file to this folder.
My code couldn't import the library and this error appeared every time I tried to use the library:
"src\Gerenciador.java:2: error: package org.json does not exist import org.json.JSONArray;"
After a while I thought it would be easier to import the library on the Ide Eclipse, but after creating the project and adding it via the Build Path option, it still didn't work. Even though the library appeared in the Libraries section in the Java Build Path.
This error: "The type org.json.JSONObject is not accessible" keeps appearing.
I don't know how to fix the problem. I think I'm calling on the library wrong, but I don't know how I should do it. If there is any information missing, let me know and I'll provide it, it's my first time asking for help on a programming forum.
Hi,
I am using java to create a custom nifi processor and i am trying to use the org.json.simple package to access some information from a json. When i try to compile my code i keep getting the error in the title. below is a my pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>1</groupId>
<artifactId>1</artifactId>
<version>1</version>
</parent>
<artifactId>nifi-processor_stuff-nar</artifactId>
<version>1</version>
<packaging>nar</packaging>
<properties>
<maven.javadoc.skip>true</maven.javadoc.skip>
<source.skip>true</source.skip>
</properties>
<dependencies>
<dependency>
<groupId>1</groupId>
<artifactId>nifi-processor_stuff-processors</artifactId>
<version>1</version>
</dependency>
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1.1</version>
</dependency>
</dependencies>
</project>I'm parsing json files using JSONArray and JSONObject but I keep getting the error shown in the title. I've downloaded org.json.jar but I don't know what to do next. Currently, org.json.jar sits in the same path as all of the other java files and classes.
Thanks!
Trying to use JSON to store some objects locally for retrieval later. Can't figure out why I'm unable to import json. Doesn't work in vim, doesn't work in vsCode, doesn't work in Eclipse.
Read online that I may need to download the json .jar and add to my build path? When googling "json download" its only scammy virus websites.
I'm on a Mac.
Edit: Added pictures
https://imgur.com/a/FlKwMIF
Thanks for the help.
Try this VS Code command...
View -> Command Palette -> Java: Clean Java Language Server Workspace
This command resolved my similar issue with VS Code not recognizing import org.json.* inside the .java files of a Gradle project even though Gradle would build and run successfully. This VS Code command is similar to IntelliJ's File -> Invalidate Caches and Restart in that it forces a refresh of the IDE's cache of available tokens and identifiers.
Side Notes:
- Make sure to have run your build tool (e.g.
gradle buildormvn install) at least once so that the required packages are downloaded to your local computer so VS Code can find them. - This command comes with the VS Code extension "Language Support for Java" from Red Hat (redhat.java) which comes bundled in the "Java Extension Pack" from Microsoft (vscjava.vscode-java-pack). You'll have to have one of these extensions installed to use it.
I've done all the Java server cleaning and still getting '''package org.apache.lucene.analysis.tokenattributes does not exist(compiler.err.doesnt.exist)'''
build.gradle:
ext.pluginApiVersion = '8.12.2'
ext.luceneVersion = '8.11.3'
dependencies {
implementation "org.apache.lucene:lucene-
core:${luceneVersion}"
implementation "org.apache.lucene:lucene-analyzers-
common:${luceneVersion}"
implementation
"org.elasticsearch:elasticsearch:${pluginApiVersion}"
implementation
"org.elasticsearch.plugin:elasticsearch-plugin-
api:${pluginApiVersion}"
implementation
"org.elasticsearch.plugin:elasticsearch-plugin-analysis-
api:${pluginApiVersion}"
}
Your code throws no errors in my project:

I think there's a cache messed it, you may
- Turn to local dependency installation folder, delete
\User folder\.m2\repository\com\alibaba\fastjson\1.2.78 - Delete the dependency
fastjsoninpom.xml - Open Command Palette and choose Java: Clean Java Language Server Workspace
- re-add the
fastjsondependency and follow the notification to synchronize project configuration.
Finally, I resolved my problem with VS Code myself. I put my solution here in case someone or I met the same problem in the future.
To solve the issue:
- I moved my maven dependencies path to else where: I created a folder
G:\maven-repo, and modified globalsettings.xmlof maven like below:
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<localRepository>G:/maven-repo</localRepository>
</settings>
- In
settings.jsonof VS Code, I added the line below, which refers to where thesettings.xmlin step 1 is:
"java.configuration.maven.globalSettings": "G:/ideaIU/plugins/maven/lib/maven3/conf/settings.xml"
Restart VS Code, execute
Java: Clean Java Language Server Workspaceas @Molly Wang-MSFT said.After restarting VS Code again, pressing the F5 key, the project finally runs correctly.

Hello I am having trouble with Java recognizing the existence of a package that comes included in a library that I have downloaded. Before it avoided its existence, vscode was telling me that the "package could not be resolved". I have tried to "clean the workspace", but it does not work. Here is what the terminal shows
Tweets.java:1: error: package tester does not exist
import tester.Tester;
Tweets.java:70: error: cannot find symbol
boolean testIsStartOfThreadByTextTweetValid(Tester t) {
symbol: class Tester
UPDATE* Here is the code I have written
import tester.Tester;
interface Tweet {
public boolean isStartOfThreadBy(String author);
public int totalLikes();
public String unrollThread();
}
class TextTweet implements Tweet{
String author;
String contents;
int likes;
TextTweet(String author, String contents, int likes) {
this.author = author;
this.contents = contents;
this.likes = likes;
}
public boolean isStartOfThreadBy(String author) {
if (this.author.equals(author))
return true;
return false;
}
public int totalLikes(){
return likes;
}
public String unrollThread(){
String s = author + "\n" + likes +"\n" + contents + "\n";
return s;
}
class ReplyTweet implements Tweet{
String contents;
int likes;
String author;
Tweet replyTo;
public ReplyTweet(String contents, int likes, String author, Tweet replyTo){
this.contents = contents;
this.likes = likes;
this.author = author;
this.replyTo = replyTo;
}
public boolean isStartOfThreadBy(String author) {
if (this.author.equals(author) && this.replyTo.isStartOfThreadBy(author)){
return true;
}
return false;
}
public int totalLikes() {
return likes + replyTo.totalLikes();
}
public String unrollThread(){
String s = replyTo.unrollThread() + author + "\n" + likes +"\n" + contents + "\n";
return s;
}
}
public class Tweets {
boolean testIsStartOfThreadByTextTweetValid(Tester t) {
TextTweet f1= new TextTweet("John", "Hello", 5);
return t.checkExpect(f1.isStartOfThreadBy("John"), true);
The jar file that I am trying to get to work is called "tester.jar" and it is within the folder/library I am working with right now for this project.

