Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VS Code: The declared package "controller" does not match the expected package ""

So, I have checked some other threads that are about this topic, such as the following:

Eclipse says package declaration does not match expected package ""

The declared package test does not match the expected package

libgdx: The declared package does not match the expected package ""

But they all deal with Eclipse (or Eclipse + Maven), and I am just using VS Code without all the fancy capabilities of an IDE or a package manager.

As the title suggests, I am getting the message: [Java] The declared package "controller" does not match the expected package ""

I get this message for every single file that I attempt to give a package using the syntax:

package myPackageName;

even if the file in question is defiantly in the right folder. This problem only occurs as a visual, i.e. everything compiles fine using javac. I have been dealing with it ever since I started using VS Code for my Java Projects.

How do I make the red squigglies and the red lettering in the file explore tab go away in the case of perceived package errors?? It drives me nutty, I can't quickly find the files that actually have errors in my project because everything is marked red except the Driver.

Here is a picture: picture

[edit] Got rid of the unrelated compile time errors So you can see it compiles.

like image 657
Isaac Yates Avatar asked Mar 23 '18 23:03

Isaac Yates


1 Answers

All classes in the package should be open on VSCode (on different tabs). Same thing happens when you want to use other public classes in same directory: it should be visible but when you run the program, you will get a compile-time error. Then again the solution is to have all classes open on different tabs. Hope it helps

like image 120
Amir47 Avatar answered Oct 29 '22 17:10

Amir47