0

I have three java files dictionary.java postings.java and invert.java

The first line for all three is:

package project1;

The folder path for these are Desktop/cps/.

I have compiled the files using (while in the directory cps):

javac -d . *.java

... which creates a folder project1 with all three .class files.

when I try to run using the following command:

java project.invert 

I get that error:

Could not find or load main class project.insert

How do i run invert.java?

The invert.java has the main class while the other two are just class definition files.

ccjmne
  • 9,333
  • 3
  • 47
  • 62
Hambuzo
  • 83
  • 10

2 Answers2

0

Folder path for all 3 files must be Desktop/cps/project1 instead of Desktop/cps/.

Packages in Java represent directories in the file system.

You must compile while being in Desktop/cps/ as javac project1/*.java

and run the program using java project1.invert

riteshtch
  • 8,629
  • 4
  • 25
  • 38
0

There maybe a typo in your execution command. It should be java project1.invert notice the 1 with project. Further the signature of main method must have String[] args argument. It should be

public static void main(String[] args)

If the access specifier is missing then it will result in compile time error.

Hope this helps.