Logan Alexander Thies
Logan Alexander Thies

Reputation: 23

"The declared package '' does not match the expected package "AssignmentOne.java"" -Java -VS Code

Why am I getting this error in VS Code?

Things I've tried:

I am attempting to only run the file, ScannerInputDemo.java, but VSCode is also attempting to run the other .java files in my /Intro To Java folder.

I've tried modifying my launch.json file to remove the configuration for the AssignmentOne.java file hoping that it wouldn't attempt to read that file

Specs: I'm using a Mac Book Pro 13", mid 2009.

My version check is:

openjdk version "11.0.7" 2020-04-14
OpenJDK Runtime Environment AdoptOpenJDK (build 11.0.7+10)
OpenJDK 64-Bit Server VM AdoptOpenJDK (build 11.0.7+10, mixed mode)

VSCode Version:

Version: 1.45.1
Commit: 5763d909d5f12fe19f215cbfdd29a91c0fa9208a
Date: 2020-05-14T08:33:47.663Z (2 wks ago)
Electron: 7.2.4
Chrome: 78.0.3904.130
Node.js: 12.8.1
V8: 7.8.279.23-electron.0
OS: Darwin x64 15.6.0

Below is a screenshot of my VS Code window showing the file hierarchy and debug results.

enter image description here

Upvotes: 0

Views: 1792

Answers (1)

Nitin Jindal
Nitin Jindal

Reputation: 45

I encountered the same issue.

Issue was in .classpath file, present in the project directory.

It contained

classpathentry kind="src" output="target/classes" path="src"

I updated it to

classpathentry kind="src" output="target/classes" path="src/main/java"

and it worked.

Upvotes: 1

Related Questions