Harshit Khanna
Harshit Khanna

Reputation: 133

The declared package "" does not match the expected package

I'm able to compile and run my code but there is always an error showing in VSCode. Earlier there was a pop up I don't remember what and I clicked "apply globally" and it's been this way since.

Output is there but so is the error enter image description here

The declared package "" does not match the expected package enter image description here

Upvotes: 13

Views: 22671

Answers (1)

alelom
alelom

Reputation: 2983

Thanks to the comment of @beatrice above, I found the answer here.

My .vscode\settings.json file had some paths explicitly added. I had added them manually when Visual Studio code was not misbehaving, by right-clicking on certain project folders and doing "add Folder to Java source path".

The solution for me was to basically remove all of them from .vscode\settings.json, replacing its contents with:

{
    "java.project.sourcePaths": [""]
}

This finally made VsCode work again.

Upvotes: 15

Related Questions