Could not find or load main class mean

0 votes
A common problem that new Java developers experience is that their programs fail to run with the error message: Could not find or load main class ...

What does this mean, what causes it, and how should you fix it?
Apr 17, 2018 in Java by Akrati
• 3,190 points
4,318 views

2 answers to this question.

0 votes

If your main method is in the class under a package, you should run it over the hierarchical directory.

Assume there is a source code file (Main.java):

package com.test;

public class Main {

    public static void main(String[] args) {
        System.out.println("salam 2nya\n");
    }
}

For running this code, you should place Main.Class in the package like directory ./com/test/Main.Java. And in the root directory use java com.test.Main

answered Apr 17, 2018 by sharth
• 3,370 points
0