vscode-java icon indicating copy to clipboard operation
vscode-java copied to clipboard

not on the classpath of project app, only syntax errors are reported

Open tapz opened this issue 5 years ago • 15 comments

Java files always give me this error in vscode:

MyCall is not on the classpath of project app, only syntax errors are reported

Environment
  • Operating System: macOS Catalina 10.15.4 (19E287)
  • JDK version: 1.8.0_40
  • Visual Studio Code version: 1.44.0
  • Java extension version: Java Extension Pack 0.90.0, Language Support for Java 0.59.1
Steps To Reproduce
  1. Open Java file in vscode
Current Result

Error

Expected Result

No error

Additional Informations

tapz avatar Apr 14 '20 14:04 tapz

Can you provide more details? like your project setup? maybe share your project?

fbricon avatar Apr 14 '20 14:04 fbricon

I can't share my project. It's a React Native project. Just a normal Java project, which compiles just fine.

tapz avatar Apr 14 '20 15:04 tapz

So I'm assuming it's an Android project then? If so, then sorry but it's not supported by vscode-java

fbricon avatar Apr 14 '20 15:04 fbricon

Yes. Android. What makes Android so different? It's my Java class after all, not any Android class.

tapz avatar Apr 14 '20 15:04 tapz

Android uses special Gradle plugins to compute the project classpath, that are not supported in Buildship, the underlying Gradle Integration plugin we delegate Gradle support to.

fbricon avatar Apr 14 '20 16:04 fbricon

@fbricon How do you solve this problem?

agusfahrurroji avatar Jun 23 '20 02:06 agusfahrurroji

@fbricon How do you solve this problem?

Android development is not supported at the moment. It will require a significant amount of work at Buildship as mentioned by @fbricon

Currently, there is no ideal solution for that but you can try the Lightweight mode by settingjava.server.launchMode to LightWeight. You will be able to use a subset of features like Go to Definition of the types inside your local source and JDK. But there are also limitations, you won't be able to navigate to the types in Android SDK, and you won't be able to build and debug.

akaroml avatar Jul 01 '20 09:07 akaroml

Add working files to the project's source path

vikashvk avatar Jul 24 '20 08:07 vikashvk

I have the same problem when using 'package package_name' , my solution is that clost it and open it again....

GreatLyndon avatar Apr 22 '21 04:04 GreatLyndon

I have the same problem:

  1. open a folder with vs code, and create a pom.xml to support multiple modules.
  2. create a maven project with Spring Initializer, e.g. demo1
  3. now, the new project demo1 will not be recognized for 'xxxx.java is not on the classpath of project xxx, only syntax errors are reported'

btw, i can clean .classpath file (e.g. git clean -dfx) and reopen the folder with vscode to solve it.

alyiox avatar May 01 '21 06:05 alyiox

I had the same problem here, but I guess that I managed to solve this, just moving the '.vscode' folder into the project folder. Into that have a JSON file pointing to the project path. When I oppened that I've tried to change the path, but had no success. When I moved the entire folder, and after restart VS Code, the error disapeer. Then, I ran a HelloWorld.java test, and it worked for me.

andremeiras avatar May 01 '21 11:05 andremeiras

In VS Code just right-click on the src (the folder which contains all java files) folder and select the " Add folder to Java source path" option. If it didn't' worked, then try to remove it first by selecting "remove the folder from Java source path" and then adding it again.

Restart once when done. Hope it works for you.

abdeali004 avatar May 14 '21 06:05 abdeali004

In VS Code just right-click on the src (the folder which contains all java files) folder and select the " Add folder to Java source path" option. If it didn't' worked, then try to remove it first by selecting "remove the folder from Java source path" and then adding it again.

Restart once when done. Hope it works for you.

Can't add to source path: Unsupported operation. Please use build.gradle file to manage the source directories of gradle project.

XilinJia avatar Jun 09 '21 11:06 XilinJia

Still it shows

unsupported operation. please use build.gradle

IAmAnshul07 avatar Jul 30 '21 04:07 IAmAnshul07

I warn you that this will happen in 2025. If you arrive in 2030, do not be alarmed, it will continue to happen.

I already get really pissed off when a feature has been buggy for a week. But when it has been buggy for more than 30 days... and seeing this I don't even bother.

Let's see if AI tells me the secret.

drakgoku avatar Feb 05 '25 18:02 drakgoku