Home java Java, “Could not find or load main class”

Java, “Could not find or load main class”




I must say right away that I am an absolute beginner in coding, and therefore I can be blunt. Here is my code:

import java.util.Scanner;
public class AreaOfCircle {
  public static void main (String [] args) {
    System.out.println ("enter radius, blyat:");
    Scanner input = new Scanner (System.in);
    float radius = input.nextFloat ();
    float area = 3.14f * radius * radius;
    System.out.println ("The area of ​​circle with radius" + radius + "is equal to" + Math.round (area));

I wrote it down and when I compiled it everything was fine, but when I tried to enable it it gave me the above error. I did not understand why, I went to the Internet, there was a tip with “java. -Classpath” but even so java could not find the code. I went to the Internet again, and realized that my knowledge was not enough to understand the actions there. I wrote the code in Sublime Text 3, I don’t know if it will help or not

Answer 1, authority 100%

If your AreaOfCircle class is started without a package (that is, there is no package declaration):

// it is assumed that you run from the directory where AreaOfCirlce.class is located
java -cp. AreaOfCircle

If there is a declaration before the class like package my.package , then you need to run it like this:

java -cp. my.package.AreaOfCircle

In general, the command line should look like this:

java -cp [folder] [full class name]


[folder] - directory where the directory tree of .class files is located
[full class name] - full class name with package indication

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions