vscode-java-debug
vscode-java-debug copied to clipboard
Could not find or load main class QuartsToGallons
PS C:\Users\ZIXUAN8368\Desktop\Java\Chapter2> cd "c:\Users\ZIXUAN8368\Desktop\Java\Chapter2" ; if ($?) { javac QuartsToGallons.java } ; if ($?) { java QuartsToGallons } Error: Could not find or load main class QuartsToGallons Caused by: java.lang.NoClassDefFoundError: QuartsToGallons (wrong name: Chapter2/QuartsToGallons)
I am new to VS Code and i couldn't figure it out how to solve this, i will need some help
pls share the specific steps to reproduce your issue.
Hi @zixuan8368, I'm an AI Support assistant here to help with your issue. While the team reviews your request, I wanted to provide some possible tips and documentation that might help you in the meantime.
Solution
- Verify whether your
QuartsToGallons.javafile declares a package. If it begins with
then you must:package Chapter2;- Compile from the folder above
Chapter2:cd C:\Users\ZIXUAN8368\Desktop\Java javac Chapter2\QuartsToGallons.java - Run it by its fully-qualified name:
java Chapter2.QuartsToGallons
- Compile from the folder above
- If you don’t intend to use packages, remove or comment out the
package Chapter2;line and then recompile & run from within the same directory:cd C:\Users\ZIXUAN8368\Desktop\Java\Chapter2 javac QuartsToGallons.java java QuartsToGallons
Other references with high confidence
- Java does not execute unless package statement is commented out
Demonstrates how a package declaration forces you to run the class using its package-qualified name (or from the correct parent folder).
https://github.com/redhat-developer/vscode-java/issues/877
The team will respond to your issue shortly. I hope these suggestions are helpful in the meantime. If this comment helped you, please give it a 👍. If the suggestion was not helpful or incorrect, please give it a 👎. Your feedback helps us improve!