skip to Main Content

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?

enter image description here

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


  1. Your class is located in the package (folder) week3.lesson.

    So you have to add the package declaration:

    package week3.lesson
    

    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

    Login or Signup to reply.
    • 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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search