TL;DR — As this unresolved 'Cannot be resolved' errors in projects with module-info.java issue reports, vscode is brain dead when it comes to JPMS and module-info.java.


The long-winded version

From my own experience, I can personally vouch for what the reporter of the above-linked vscode issue reports…

…I've tried both Gradle and Maven…

…I find that Gradle and Maven will automatically refresh the classpath file and remove my modifications to it, which will bring back the errors…

…there needs to be module path information set in the classpath file in order for Eclipse to be happy, but there is no good way to do with that from Gradle or Maven…

Proof that it's a vscode issue is that the exact same project — unchanged except for the removal of your comment — compiles perfectly fine in IntelliJ…

Since your project uses neither Maven nor Gradle — opting instead to use file-based dependency mgt with the jar in the lib folder — you're in even worse shape because you've eliminated the option of applying any JPMS-enabling plugins that could resolve the issue.

For example, by adding the following pom.xml with the appropriate configuration for the maven-compiler-plugin to my experimental version of your project…

…
<dependencies>
    <dependency>
       <groupId>org.json</groupId>
        <artifactId>json</artifactId>
        <version>20200518</version>
    </dependency>
</dependencies>
<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.8.1</version>
            <configuration>
                <source>11</source>
                <target>11</target>
                <compilerArgs>
                    <arg>-Xlint:unchecked</arg>
                    <arg>--add-modules</arg>
                    <arg>org.json</arg>
                </compilerArgs>
            </configuration>
        </plugin>
    </plugins>
</build>
…

…Maven does its magic and processes the module-info.java successfully…

I've successfully resolved other Stackers' JPMS woes by helping them apply that mrJar plugin mentioned in that vscode bug report. So if you're open to using Gradle instead of Maven, I could likewise advise you on how to configure that plugin too.

Answer from deduper on Stack Overflow
Top answer
1 of 1
1

TL;DR — As this unresolved 'Cannot be resolved' errors in projects with module-info.java issue reports, vscode is brain dead when it comes to JPMS and module-info.java.


The long-winded version

From my own experience, I can personally vouch for what the reporter of the above-linked vscode issue reports…

…I've tried both Gradle and Maven…

…I find that Gradle and Maven will automatically refresh the classpath file and remove my modifications to it, which will bring back the errors…

…there needs to be module path information set in the classpath file in order for Eclipse to be happy, but there is no good way to do with that from Gradle or Maven…

Proof that it's a vscode issue is that the exact same project — unchanged except for the removal of your comment — compiles perfectly fine in IntelliJ…

Since your project uses neither Maven nor Gradle — opting instead to use file-based dependency mgt with the jar in the lib folder — you're in even worse shape because you've eliminated the option of applying any JPMS-enabling plugins that could resolve the issue.

For example, by adding the following pom.xml with the appropriate configuration for the maven-compiler-plugin to my experimental version of your project…

…
<dependencies>
    <dependency>
       <groupId>org.json</groupId>
        <artifactId>json</artifactId>
        <version>20200518</version>
    </dependency>
</dependencies>
<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.8.1</version>
            <configuration>
                <source>11</source>
                <target>11</target>
                <compilerArgs>
                    <arg>-Xlint:unchecked</arg>
                    <arg>--add-modules</arg>
                    <arg>org.json</arg>
                </compilerArgs>
            </configuration>
        </plugin>
    </plugins>
</build>
…

…Maven does its magic and processes the module-info.java successfully…

I've successfully resolved other Stackers' JPMS woes by helping them apply that mrJar plugin mentioned in that vscode bug report. So if you're open to using Gradle instead of Maven, I could likewise advise you on how to configure that plugin too.

🌐
YouTube
youtube.com › watch
Importing json in java visual studio code | the import org.json cannot be resolved, Solved! - YouTube
In this video, we will learn how to import jsonsimple in java visual studio code project or we will learn to solve following error in visual studio codethe i...
Published   October 11, 2020
🌐
Reddit
reddit.com › r/javahelp › error: org.json does not exist
r/javahelp on Reddit: Error: org.json does not exist
May 25, 2022 -

I 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 errors
Top answer
1 of 2
4
I'm not used to VSCode but evidently the library is used to compile but not at runtime. Perhaps you have to add it somewhere else, maybe in the run configuration? PS if you want to keep your sanity while developing in java, i strongly suggest to use maven to automate dependencies (unless this is homework then maybe not).
2 of 2
1
Please ensure that: Your code is properly formatted as code block - see the sidebar (About on mobile) for instructions You include any and all error messages in full You ask clear questions You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions. Trying to solve problems on your own is a very important skill. Also, see Learn to help yourself in the sidebar If any of the above points is not met, your post can and will be removed without further warning. Code is to be formatted as code block (old reddit: empty line before the code, each code line indented by 4 spaces, new reddit: https://imgur.com/a/fgoFFis ) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc. Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit. Code blocks look like this: public class HelloWorld { public static void main(String[] args) { System.out.println("Hello World!"); } } You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above. If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures. To potential helpers Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice. I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
🌐
DevPress
devpress.csdn.net › cloud › 632608bf6213ca4d56909ec7.html
org.json cannot be resolved to a module?_rxjava_开发云应用-开发云
September 18, 2022 - Proof that it's a vscode issue is that the exact same project — unchanged except for the removal of your comment — compiles perfectly fine in IntelliJ… · Since your project uses neither Maven nor Gradle — opting instead to use file-based dependency mgt with the jar in the lib folder — you're in even worse shape because you've eliminated the option of applying any JPMS-enabling plugins that could resolve the issue.
🌐
Reddit
reddit.com › r/javahelp › can't import "json-20240303" library into my project.
r/javahelp on Reddit: Can't import "json-20240303" library into my project.
June 17, 2024 -

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.

Top answer
1 of 3
2
Show your pom.xml
2 of 3
1
Please ensure that: Your code is properly formatted as code block - see the sidebar (About on mobile) for instructions You include any and all error messages in full You ask clear questions You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions. Trying to solve problems on your own is a very important skill. Also, see Learn to help yourself in the sidebar If any of the above points is not met, your post can and will be removed without further warning. Code is to be formatted as code block (old reddit: empty line before the code, each code line indented by 4 spaces, new reddit: https://i.imgur.com/EJ7tqek.png ) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc. Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit. Code blocks look like this: public class HelloWorld { public static void main(String[] args) { System.out.println("Hello World!"); } } You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above. If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures. To potential helpers Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice. I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
🌐
GitHub
github.com › microsoft › vscode-java-debug › issues › 926
The import org.junit cannot be resolved (VSCode) · Issue #926 · microsoft/vscode-java-debug
December 19, 2020 - I can't use JUnit test framework with VSCode, get message "The import org.junit cannot be resolved". I tried: Installed all recommended Java extension and then some more. Downloaded junit-platform-console-standalone-1.7.0-M1 jar file and pointed settings.json to it.
Author   microsoft
🌐
GitHub
github.com › stleary › JSON-java › issues › 514
Visual Studio Code not recognizing json.org.simple as a dependency · Issue #514 · stleary/JSON-java
April 29, 2020 - Hi, I'm working on a project with 3 other people and they have downloaded and successfully used this package. I am using Visual Studio Code and they are using Eclipse and jGrasp. However, I keep getting compilation errors for this packag...
Author   stleary
🌐
Linus Tech Tips
linustechtips.com › software › programming
How to import JSON simple package into Java? (Only using VSCode, not Maven/other IDEs) - Programming - Linus Tech Tips
September 3, 2022 - Hi there, How can I import the json jar file into my project to obtain the ability to handle JSON files? I need it so that the import code works and I can actually use it in my project. JSON jar image: Import code: import org.json.simple.JSONArray; import org.json.simple.JSONObject; import org.js...
Find elsewhere
🌐
Microsoft
social.msdn.microsoft.com › Forums › vstudio › en-US › b30c9d1b-eb25-4d8e-8362-b05b7f3cc2f8 › jsonobject-cannot-be-resolved
JSONObject cannot be resolved | Microsoft Learn
The only way I was able to get JSONObject to get recognized was to add the missing dependency org.json to pom.xml. I created a similar app service and added an index.jsp and pom.xml using Kudu and didn't have any success.
🌐
Talend
community.talend.com › s › feed › 0D53p00007vCk2bCAC
import org.json.
October 9, 2015 - Loading · ×Sorry to interrupt · Refresh
Top answer
1 of 13
243

I ran into a similar issue. The solution was to remove everything from VS Code's workspace storage directory, which was located at $HOME/Library/Application Support/Code/User/workspaceStorage/.

I found this solution here: https://github.com/redhat-developer/vscode-java/wiki/Troubleshooting#clean-the-workspace-directory

Update: This can now be done from within VS Code as of Language Support for Java(TM) by Red Hat Version 0.33.0. Open the command palette and type "java clean" (see official description in link).

2 of 13
47

As already mentioned previously, you require to clean the project, but that is a bit difficult thing because every folder is a Guid, and you do not know which one to clear, thus requiring you to delete everything. Starting with 0.33.0 version of the plugin you can automatically do that from within the IDE as well, use CTRL + Shift + P and type, java clean, and IDE will show you the suggestion tip for, Java: Clean the Java language server workspace. Upon selection, agree and restart the IDE. It will clean the language server workspace for you.

Another approach can be, the Maven tools within the IDE. If you have this plugin installed, you can use the side bar and utilize the Maven project helper options to perform actions like, clean, install, and package etc. For example, here is the project I am having and the options this shows,

That can be used, graphically, to manage your Maven-based projects. Also, this would work with the Java Extension Pack, not sure yet as to how it would behave with other extensions.

🌐
GitHub
github.com › microsoft › vscode › issues › 36935
VSCode shows .json file imports as error. · Issue #36935 · microsoft/vscode
July 3, 2018 - You must be signed in to change notification settings · Fork 39.6k · Star 184k · New issueCopy link · New issueCopy link · Closed · Closed · VSCode shows .json file imports as error.#36935 · Copy link · Assignees · Labels · upstreamIssue identified as 'upstream' component related ...
Author   microsoft
🌐
Chief Delphi
chiefdelphi.com › technical › java
Unable to add Json Dependency in build.gradle - Java - Chief Delphi
October 29, 2018 - Hi. I added this line: compile group: ‘org.json’, name: ‘json’, version: ‘20180813’ in the dependency section of build.gradle but I get an error and I have looked everywhere online. I even talked to Jason on 2073 who was also confused. Error: > Could not resolve all files for ...
🌐
Qlik Community
community.qlik.com › t5 › Design-and-Development › org-json-cannot-be-resolved-to-a-type › td-p › 2205709
Solved: org.json cannot be resolved to a type - Qlik Community - 2205709
June 12, 2020 - Hi Have you import external jar which contains the packget org.json.x using tLibraryLoad component in the beginning of job?
🌐
Reddit
reddit.com › r/learnpython › vscode saying import could not be resolved but it definitely is
r/learnpython on Reddit: vscode saying import could not be resolved but it definitely is
July 9, 2021 - I got rid of the warning in vscode/windows by adding the directory to my PYTHONPATH environment variable and restarting vscode.
🌐
Chief Delphi
chiefdelphi.com › technical › java
Import cannot be resolved - Java - Chief Delphi
April 3, 2022 - I recently pulled the latest version of my team’s robot from Github. Since the last time I pulled into my workspace the software team added PhotonVision. After pulling the latest version I can build the software without a problem, but Intellicode (I think it is intellicode) says that the it cannot resolve the import: import org.photonvision.PhotonCamera; or any other import for org.photonvision.