Unable to find or load the main file class.java

Asked

Viewed 6,763 times

1

Hi,

I’ve been trying to make a code run in a new environment, but I’m not succeeding.

Whenever I open the cmd and execute the java arquivo.java I have as return the error Não foi possível localizar nem carregar a classe principal arquivo.java.

The class has already been compiled without any problems and, theoretically, everything is right.

My environment variables:

JAVA_HOME:

C: Program Files Java jdk1.8.0_05

CLASSPATH:

.;%JAVA_HOME% lib;%JAVA_HOME% lib tools.jar;%JAVA_HOME% lib dt.jar;%JAVA_HOME% lib htmlconverter.jar;%JAVA_HOME% jre lib;%JAVA_HOME% jre lib rt.jar;

PATH:

*irrelevant variables *;%JAVA_HOME% bin

Any idea what I might be doing wrong?

  • Check if your code has the Main method

  • Hi. The code has the main method. It seems more general, since I’m not able to execute even extremely simple classes that I created just to test.

1 answer

3


It is necessary to compile the class before running.

And to rotate, in the class it is necessary to contain the main method.

Ex:

public class Arquivo {
  public static void main(String args[]) { 

  }
}

Command to compile

javac Arquivo.java

Command to run, but cannot and does not need to use the extension.

java Arquivo
  • It seems that the error was that I ran with the . java extension and inside the package folder. Running outside the package folder with java pacote/classe it works. Valeu :)

  • And @Lucas, you can even inside the folder (java classe). The error was to put . java.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.