-2

I have java and javac installed on a unix server at my school.

I have a java file called Test.java that looks like:

package Spill;
import java.util.Scanner;

public class Test {

  public static void main(String[] args) {

  }
}

Test calls a class called Grid in a file called Grid.java
and Grid calls a class called Cell in a file called Cell.java

All three files are in a directory called Assignment

While in Assignment I use the command:

javac Test.java Grid.java Cell.java

and three files appear called Test.class Grid.class and Cell.class appear.

I set all files in directory to have read, write and execute permissions.

Finally I use the command:

java Spill.Test

and get the error

Error: Could not find or load main class Spill.Test

I also tried

java Test

and got the same error

Error: Could not find or load main class Test

What am I missing?

Edit: Not an exact duplicate, since the linked article had all the possible reasons for the error message, but I have information in my question that tells us it could only be not creating a sub-directory to correspond with the package name.

CSStudent7782
  • 618
  • 1
  • 5
  • 21
  • does this run locally on your own machine? And did you import the other two classes? – hysoftwareeng Mar 22 '18 at 17:14
  • I did import the other two classes, Lebron James, but I have not tried running them on my local machine. They compiled fine tho, since javac worked, so that shouldn't be the issue. – CSStudent7782 Mar 22 '18 at 17:23

1 Answers1

-1

Your three classes must be in folder named Spill relative to your current folder, and you need to add that to your CLASSPATH (either with . or in full). The package is part of the class name in Java and must mirror on the disk storage. Assuming you're currently in the Spill folder,

cd ..
java -cp . Spill.Test
Elliott Frisch
  • 198,278
  • 20
  • 158
  • 249
  • Thank you, thank you. This is what I was missing. I've been spoiled by IDE's in the past, and I didn't realize I had to create corresponding directories for my packages. – CSStudent7782 Mar 22 '18 at 17:25