Antonis
Antonis

Reputation: 23

Cant find or load main class

When I try to run a java program in the cmd it displays the messege "Could not find or load main class". The problem occurs when there is a package involved in the program, otherwise it works fine.

The code is:

package myPackage;

public class index {

public static void main(String [] args){

    System.out.println("Hello World");
}
}

I've tried writting in cmd: javac (name of package) . Class name, but still doesnt work.

Upvotes: 0

Views: 51

Answers (1)

SSP
SSP

Reputation: 2670

The issue was that the class path needs to be set for each command (javac and java):

Attempted Steps

Compile index.java from the top_level. do not use sub package.

$javac -cp . importpackage/subpackage/index.java

Upvotes: 1

Related Questions