I know this question asked a lot and i read most answer but non of them solved my problem.
I’m kinda new at java but i’m using vscode over than a year. I never come across this kinda problem on other languages, libraries, frameworks.
When i open vscode, a couple seconds later, all my java source code files turns red and the error is
The declared package <package name> does not match the expected package ""
but jokes on me i dont have any packages on those files. when i open the source code files, some of them stays same, others turn normal?
I saw the extensions can cause this problem, like Java Language Support – by George Fraser
VS Marketplace Link: https://marketplace.visualstudio.com/items?itemName=georgewfraser.vscode-javac
I uninstall that, only microsoft’s and red hat’s extensions left. I have reloaded window a couple hundred times, close folder ets. I have no idea what is going on, please help.
2
Answers
Your class is located in the package (folder)
week3.lesson
.So you have to add the package declaration:
to the class.
BTW: Take care of java naming conventions. Class names should start with upper case character and be camelCase not snake_case.
In your case your class should be named:
DrawCards
Hover the mouse over the red wavy line to view error messages.
Ctrl+Shift+P –>
Java: Clean Java Language Server Workspace
and restart vscode.If you can run the code normally, you can ignore the warning.