Search code examples
javajavac

java error: Could not find or load main class ass1.insert


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.


Solution

  • 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.