I am running a build task in a java project in Visual Studio Code.
The warning in the “PROBLEMS” tab:
[myfile].java is a non-project file, only syntax errors are reported
It refers to the first line where I load in the class file containing the main():
package [the project folder]; import [the project folder].[the file with other classes].*;
- I can only avoid the warning by copying the files’ text (the code text itself) into new java files of a new project in a new unrelated folder. The code itself is correct and compiles without errors. Actually, this is the answer, but it is much manual work.
- When I just copy the java files of the project with the warning message into a new folder, the warning still appears!!!! (!)
- When I just copy the whole project folder to a new place, the error remains as well, of course.
I guess that copying text into new java files with the same names and the same folder structure is different from copying the files themselves because the files probably get tagged by VS Code, so that they have a project stamp even when the folder structure is destroyed. Perhaps this supports recovering the project structure from recovered raw files? Could this be the problem of this Visual Code warning?
I have already deleted the workspaceStorage incl. restart.
I had other errors before, this is just the last step.
- first error was: How can I fix build failed, do you want to continue? in vscode
- second error was: Visual Studio Code – Java – Import Errors and More
I got the same warning as well. It was simply because I had two Java projects in the same vscode workspace. Once I’ve moved projA out of the workspace, the warning is gone for projB.
WorkspaceRoot │ projectA └───projectB
At this point, I think the most likely solution is to have one Java (Maven) project for one workspace. Otherwise I guess vscode will treat they all as one project and they’ll interfere with each other.
I think I found the answer. 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.