How to avoid VS Code warning: “[myfile].java is a non-project file, only syntax errors are reported”

We Are Going To Discuss About How to avoid VS Code warning: “[myfile].java is a non-project file, only syntax errors are reported”. So lets Start this Java Article.

How to avoid VS Code warning: “[myfile].java is a non-project file, only syntax errors are reported”

  1. How to avoid VS Code warning: “[myfile].java is a non-project file, only syntax errors are reported”

    Try cleaning the Java language server workspace:
    CMD+SHIFT+P (CTRL+SHIFT+P ON WINDOWS) to show command palette
    Choose “Java: Clean the Java language server workspace”
    Restart and Delete
    Just worked for me.

  2. VS Code warning: “[myfile].java is a non-project file, only syntax errors are reported”

    Try cleaning the Java language server workspace:
    CMD+SHIFT+P (CTRL+SHIFT+P ON WINDOWS) to show command palette
    Choose “Java: Clean the Java language server workspace”
    Restart and Delete
    Just worked for me.

Solution 1

Try cleaning the Java language server workspace:

  1. CMD+SHIFT+P (CTRL+SHIFT+P ON WINDOWS) to show command palette
  2. Choose “Java: Clean the Java language server workspace”
  3. Restart and Delete

Just worked for me.

Original Author Of This Content

Solution 2

I got the same warning simply because I had two Java (Maven) projects in the same vscode workspace. Once I moved projectA out of the workspace, the warning for projectB is gone.

WorkspaceRoot
│   projectA
└───projectB

My current solution is to have one Java (Maven) project for one workspace, i.e,
one Maven project per vscode workspace.

My guess is that vscode treats all Java projects inside the same workspace as as one project and hence, the projects interfering with each other.

Original Author Of This Content

Solution 3

This is an answer for those who do not use Maven.

The whole problem came up from loading not the direct project folder, but the parent folder, though the projects had been developed in their direct project folders from the start.

FOLDER1 (parent) contained

  • FolderA (direct project folder of java files)
  • FolderB (direct project folder of java files)

I have written the projects separately. But one time I opened the FOLDER1 in VS Code instead. That seems to have merged the 2 projects to just one project. After this, I changed back to opening only the FolderA/B and got the warnings that are reported in the question.

Now that I have opened FOLDER1 again and made both FolderA/B projects run without warnings (perhaps you might just comment out everything without fixing anything, but that is untested), opening the isolated FolderA/B projects threw no warnings either. Seems as if VS Code makes opening the parent folder the start of a new project which interferes with the child projects.

And the reason why I had a warning was a code error inside the other project’s folder in the end (not important, but I had forgotten to load the local package needed for “FolderA” project at the start of some java file).

Whatever error I had, the warning was confusing, as I was only working on project “FolderB” which had nothing to do with “FolderA” and which had no code issue. This led to the strange effect that I got the warning of the “FolderA” project also in my “FolderB” project, because VS Code considered both as one project.

Original Author edited Jun 24, 2021 at 17:29 Of This Content

Solution 4

I struggled with this for a long time but did not find a proper solution on the internet. I somehow managed to do it by following these steps:
Here are the actions that I’ve performed:

  1. There are folders you see in your left pane. (or press crt+shift+e to open the left pane).
  2. Right-click on them one by one and press “Add folder to Java Source
    Path.”

The one suggested in the solutions didn’t solve my problem 100%. The problem with this extension occurred “Language Support for Java(TM) by Red Hat,” which let our folder away from the source path.

Original Author Of This Content

Conclusion

So This is all About This Tutorial. Hope This Tutorial Helped You. Thank You.

Also Read,

Siddharth

I am an Information Technology Engineer. I have Completed my MCA And I have 4 Year Plus Experience, I am a web developer with knowledge of multiple back-end platforms Like PHP, Node.js, Python and frontend JavaScript frameworks Like Angular, React, and Vue.

Leave a Comment