redhat-developer / vscode-java

Java Language Support for Visual Studio Code
Eclipse Public License 2.0
2.08k stars 442 forks source link

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

Open tapz opened 4 years ago

tapz commented 4 years ago

Java files always give me this error in vscode:

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

Environment
Steps To Reproduce
  1. Open Java file in vscode
Current Result

Error

Expected Result

No error

Additional Informations
fbricon commented 4 years ago

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

tapz commented 4 years ago

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

fbricon commented 4 years ago

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

tapz commented 4 years ago

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

fbricon commented 4 years ago

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.

agusfahrurroji commented 4 years ago

@fbricon How do you solve this problem?

akaroml commented 4 years ago

@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.

vikashvk commented 4 years ago

Add working files to the project's source path

GreatLyndon commented 3 years ago

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

ousiax commented 3 years ago

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.

andremeiras commented 3 years ago

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.

abdeali004 commented 3 years ago

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.

XilinJia commented 3 years ago

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.

IAmAnshul07 commented 3 years ago

Still it shows

unsupported operation. please use build.gradle