Unix环境下Java报错:无法找到或加载主类问题求助
Hey, let's break down why this is happening and how to fix it quickly. Your Test.java has a package Spill; declaration at the top, which means Java expects the compiled .class files to live inside a Spill subdirectory—right now, they're just sitting directly in your Assignment folder, so the JVM can't locate them properly within the package structure.
Here's what you need to do step by step:
1. Set up the correct directory structure
First, create a Spill folder inside your Assignment directory:
mkdir Spill
2. Recompile with the right output path
Use the -d flag with javac to tell it to place the compiled class files into the correct package directory (the . means "current directory", and javac will auto-populate the Spill folder for you):
javac -d . Test.java Grid.java Cell.java
After running this, you'll see your three .class files inside the Spill subfolder.
3. Run the main class properly
From your Assignment directory, run the class using its full package-qualified name (no .class suffix needed!):
java Spill.Test
Quick note:
You don't even need to manually create the Spill folder first—using javac -d . will automatically generate the directory structure that matches your package declaration. Java is strict about matching package names to folder structures, so skipping this step will always lead to class-not-found errors.
内容的提问来源于stack exchange,提问作者CSStudent7782

