0

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.

Antonis
  • 23
  • 3
  • what is the file name of java program? – Kiran Maniya Sep 28 '19 at 07:13
  • Possible duplicate of [What does "Could not find or load main class" mean?](https://stackoverflow.com/questions/18093928/what-does-could-not-find-or-load-main-class-mean) – SSP Sep 28 '19 at 07:29

1 Answers1

1

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
SSP
  • 2,650
  • 5
  • 31
  • 49