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 Visual Studio 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 Studio Code warning?
I checked other threads before, and this is just the last step.
How can I fix "build failed, do you want to continue"? In Visual Studio Code
Visual Studio Code - Java - Import Errors and More
--> Thus, I cleaned Visual Studio Code's workspaceStorage (on Windows: C:\Users\USER\AppData\Roaming\Code\User\workspaceStorage) and restarted without success.
Try cleaning the Java language server workspace:
Cmd + Shift + P (Ctrl + Shift + P on Windows) to show the command palette
Choose "Java: Clean the Java language server workspace"
Restart and Delete
It just worked for me.
I got the same warning simply because I had two Java (Maven) projects in the same Visual Studio Code workspace. Once I moved projectA out of the workspace, the warning for projectB was gone.
WorkspaceRoot
│ projectA
└───projectB
My current solution is to have one Java (Maven) project for one workspace, i.e, one Maven project per Visual Studio Code workspace.
My guess is that Visual Studio Code treats all Java projects inside the same workspace as as one project and hence, the projects interfering with each other.
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 Visual Studio Code instead. That seems to have merged the two 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. It seems as if Visual Studio 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 Visual Studio Code considered both as one project.
I struggled with this for a long time, but I 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:
There are folders you see in your left pane. (or press Ctrl + Shift + E to open the left pane).
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.
Today I ran into this problem while going off-script during an Intro to Java tutorial video and somehow fixed it. This solution may not work for everyone.
Problems (1): [myfile].java is a non-project file, only syntax errors are reported.
How I fixed it...
I went to Java in Visual Studio Code and read sections "Working with Java source files" and "Working with Java projects". Basically, when working with "Java projects" in Visual Studio Code, you must have the necessary extensions installed to work with those project files.
In my case, I needed to build a Maven project supported through the extension "Language Support for Java by Red Hat" and "Server Connector by Red Hat", since one of the extensions did not come with Visual Studio Code's "Coding Pack for Java - Windows" or the "Java Development Kit: Amazon Corretto".
Once I had my extensions downloaded I opened the Command Palette (Ctrl + Shift + P) and typed "Java:Create Java Project" → "Maven" → "Maven-Archetype-Quickstart" → "1.4" → name] input group id → [name] input artifact id → then selected the folder I created that contained my Java file with the original error code (shown above). Once it was done processing, I reopened Visual Studio Code and opened my folder. Ran the program and the error went away.
You may have to copy/move your files manually or press Ctrl + Shift + E to open the left pane and add whatever you need to the Java Source Path.
I renamed the package which contains "[myfile].java is a non-project file, only syntax errors are reported" and it worked for me.
For me, removing the code folder in the C:\Users\yourHome\AppData\Roaming path solves the problem.
I have used the Visual Studio Code editor first-time for Java and I faced this issue with my simple Hello, World! program.
I tried to clean the editor's workspace, but the issue wasn't resolved.
Then, I created a folder named mypractice in the C:// drive. Following that, added the same in the Visual Studio Code workspace, and then created a Java file in that newly created workspace.
When I ran that file, it worked without any warnings or errors.
Instead of directly opening the Main.java file with Visual Studio Code Don't do this.
Open the folder in Visual Studio Code by selecting the 'Open with code' option after right clicking it in the folder and then run the program so it wont show that problem again Do this.
This is what helped me getting rid of that problem (Main.java is a non-project file, only syntax errors are reported), so I shared.
You should add your folder (in which your particular file is) to the workspace.
I have been running it a Dev Container/Docker image and multiple rebuilds have not been helping with this error. It has turned out I have accidentally created the directory in the root of the tree the current user had no access to. It has been the source of the issue.
I've been having some struggles with building my app after Reinstalling Android Studio. The cues I've gotten have been related to either Java location or installation. With the jre already installed it seems more likely not to be an issue with JAVA.
I've tried importing my project, copy and pasting from .txt files, reinstalling java, redefining java PATH, changing build dependencies, downloading command line sdk manager to build outside of the ide, erasing build caches, and I also let Android Studio rewrite properties.profile when importing Android Studio Project.
Another strange thing, when I create a directory in the project structure it shows up when the ide is initiating before gradle builds. After gradle builds the folder is no longer visible.
EDIT
error: package R does not exist
error: cannot find symbol class appcompat
UPDATE
This seems like a common problem. I've tried to follow most of the current questions on java incompatiblity but still haven't come up with a work around. I downloaded oracle's jdk (unnecessarily) and pointed the studio project at it. Created a shortcut using the jdk java.exe and placed it in Studio core, added java to the PATH which allowed gradlew build in the terminal to initiate but not complete. What are the next steps?
UPDATE
Just in case somebody else stumbles onto this. This post and also this one got me there.
The fix ended up being an import of the .R file. com.example.android.recyclerview.R Hope it can help
I create my project using the LibGDX setup tool and import it using eclipses, but when I test the project, without making any modifications, No windows pop up, and the program terminates.
I've tried both importing it as a Gradle and as a project.
I had the project working 1 week ago, but I cannot seem to get the project to run anymore.
Previous versions of LibGDX and Eclipse dont work either
Not sure if this will help you or not:
When you create your libGDX project, create it in folder that is NOT within the workspace folder you wish to use for Eclipse - that can cause quite a lot of unexpected results.
A basic setup as follows has always worked for me, first time, every time:
C:\MyProjects\MyLibGdxProject\libGDX <- Target folder for libGDX (not within Workspace)
C:\MyProjects\MyLibGdxProject\workspace <- Workspace for Eclipse
I am using this framework for one of my projects and i have problems keeping it up to date. It is a little old, uses ant to build the components and is meant for eclipse. I usually use android studio and use gradle to build from interface(not command line).
The project has a host and plugins that are loaded from a server. The plugins are compiled from the command line cmd from windows using "tools/update.sh workspace" and "ant release" commands.
What i succeded so far:
I manually copyed the files from the host component and succeded without too much stroogle to do an android studio project and build it with no errors. And it succesfully loading the plugins.
On the plugin side I have to projects: for every new plugin i do a special android studio project and after everything is ok I adapt the code and copy it to a special template like eclipse project(i edit it with notepad++ no need for eclipse) and i build it with "ant release". That apk then i move it to server.
You see now that it is a little strange but somehow I made it to work. Problem is I'm always on the edge, I almost make it every time with little hacks to pass the build process. I think it is because i work in a mixed situation. I want to port everything on android studio and gradle. And hopefully build everything from the android studio command line.
The host builds in a jar file and is used in the plugin build.
I will put the new source code on request, till then you can see it in action here
To be more specific, the impassable bug appeared when i used MediaPlayer on the plugin. I had to move the wav files on the host witch is opposed to the framework design. But this is anyway the tip of the iceberg. So i would like to port everything from ant to gradle, and eclipse to android studio.
Thanks for your help.
If you have any existing project open in your Android Studio then just close that project. After your project is closed, it will show you a Welcome screen popup, there you can select Import Project option and it will automatically convert your project into Android Studio Project.
Here is what it will look like
I am currently developing an application with my software engineering classmates. I am experiencing a few issues with Eclipse, however. But first, some information about my Eclipse: I am running version: Juno Service Release 2 with a build id of 20130225-0426. I am running Eclipse on my MacBook with OS X Mountain Lion 10.7.5. I am using SVN to upload and download the project to a repository through assembla.com.
First, Eclipse will not recognize any errors. If I purposely type random characters, Eclipse does not underline them with red.
Next, whenever I type "this.whatever" or "# for javadoc" I receive the following message: "this compilation unit is not on the build path of a Java project." I can click "OK" and continue with no problem though.
Finally, whenever I attempt to run the program I receive this message:"The selection cannot be launched, and there are no recent launches."
Other notes: I do not have any of these issues with any of my other projects in my workspace. I also have another project using the assembla repository that does not contain these issues. These issues just occurred all of the sudden.
Edit: None of the other members in my group are experiencing these issues. I have attempted to download the project from the repository on a different machine and I still have these problems. I have attempted to delete the project from my workspace and re-download. Still a no go.
Update: I even installed the Android Development Kit and used the included copy of Eclipse. It will still not work properly.
What is going on with my Eclipse?
Since I guess you're in start phase of android coding and you're not addicted to a special IDE, I strongly recommend the IntelliJ IDEA instead of Eclipse for Android development. I have tried Eclipse already and because of its weaknesses, now I'm using IntelliJ. Eclipse is not the best IDE for Android development and have a long way to become the one.
IntelliJ IDEA
I suggest you try installing the ADT bundle in a new location and see if you still have these problems. The ADT bundle includes the latest Android SDK along with a version of Eclipse with the ADT (the Android Developer Tools plugin) already installed and configured. It's possible that you have (or have had in the past) other Eclipse plugins that affect how the Java tools in Eclipse work, possibly in a way that interferes with ADT. I have personally had problems like this in the past with tools like Aptana, where even after uninstalling there would be problems.
Eclipse is telling you already with the above error message: You don't have your sources on a build path, but just in some folder.
Either you have created a simple project instead of a Java project, which then also doesn't do anything Java specific. Or you have created your Java files in plain folders, instead of source folders.
The best way to sort this out is to create a new Java project using the Eclipse "New..." wizard from the main menu. Compare the result of that to your project. The two important things are: The project has an icon with a small "J" overlayed. The Java sources are shown in packages, which themself are in source folders (with a package overlay), not in simple folders.