Error: unable to locate or load main class

Asked

Viewed 2,968 times

0

I’m looking for the solution to the following problem, I do an "Olámundo" in Netbeans and it’s compiling, doing or other in Notepad++, I can create the class with javac Hi.java, but when I put java Hi, the following error appears:

"Error: unable to find or load main class Hi"

NOTE: All the forums I search talks about the configuration of JAVA_HOME, PATH and CLASSPATH, all of them have already been set, when I put to show in Prompt the version appears normally...

How can I fix this, how can I run on Prompt?

Here are prints below the folder, notepad, prompt and test running normally in Netbeans:

inserir a descrição da imagem aqui

  • 2

    Edit the question and post your class

  • I posted the basic test code... Oi.java and Oi.class are in the folder

  • 1

    Who negatived does not understand anything of java or did not understand the question, because the problem here has nothing to do with code and the image is valid to understand the problem.

1 answer

3


You are probably trying to run the class without compiling. You need to compile the. java file first:

javac Oi.java

and then execute:

java Oi

See, the class is working normally:

inserir a descrição da imagem aqui

Note: Make sure the class has the same file name if the class is called MinhaClasse, the file should also be called MinhaClasse.java.

In the print, your file is called Hi Java., but the class signature is under a different name(public class Oie)

Obs2.: If you have package information in the class, the compiler will search for these folders, and as you will not find it will give this error. Remove package information unless you have package folder hierarchy.


Also try the command below, where the jvm will force classpath as the current folder and look for the class only inside it:

java -cp . Oi

In this answer and in this one of Soen’s has more detailed explanations of the reasons that may cause this problem.

  • Okay, thank you very much!!! :)

Browser other questions tagged

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