vscode-java
vscode-java copied to clipboard
The declared package "package" does not match the expected package ""- ( Java(536871240) )
When I package the Java file and I package it with the name of the upper directory, it shows the error at title.
Environment
- Operating System: Windows 10
- JDK version: 15
- Visual Studio Code version: Latest Stable Build
- Java extension version: Latest
Current Result
error highlight
Expected Result
No error highlight
Additional Informations
It works fine when I compile and run but it highlights the name and shows a error in editor
Could you please share a minimum sample project to help reproduce this issue?
I'm getting the same error in Maven projects that are setup as Java 9 modules. For example:
- https://github.com/Glusk/caesar
I am, however, currently using Java 11.
I am facing same issue with my gradle java projects. windows 10. Gradle 4.10.3 using 1.8 jdk compatible source. add jdk 17 and pointed java home to jdk 17 in settings.json Still I get compilation errors in VS Code editor even though gradle builds correctly builds . Here is the error I get :
"The project was not built since its build path is incomplete. Cannot find the class file for java.lang.Object. Fix the build path then try building this project" When I try to go and try configuring build path the source and output settings are readonly. I get following error in editor :
The declared package "com.abc.xyz.api" does not match the expected package "src.main.java.com.abc.xyz.api". My folder structure is as below :
My-project ( root project folder) -- .gradle -- build.gradle -- gradle.properties src main java com abc xyz api *.java
I am also getting this on one of 13 of my interdependent maven projects. Only one of them and I can't figure out what is different about this one. I have checked very carefully the .project, .settings, .classpath, and pom.xml files and can find nothing different that would cause this one to give these warnings. I get The declared package "net.crowmagnumb.xxx" does not match the expected package "src.main.net.crowmagnumb.xxx" for every single class file in this module. Yet, when I open up the file it then recompiles it just fine and the error goes away in the Problems` tab. Also, if I run my main application which depends on this module it runs completely fine so it is internally compiling just fine.
But this problem makes it so that the Problems tab is useless for me to evaluate what is affected when I make a change to my code. When I was using Eclpse this was my main way of refactoring my code. Make the change and immediately see all the places it was broken and fix them. So any ideas on what could be causing this would be greatly appreciated. :) Cheers!
Has any of you solved this issue yet? I am also getting the same error on NeoVim with jdtls