Error: can not locate or load main class

0

I'm trying to solve the following problem, I make a "Hello" in Netbeans and it's compiling, I do or in Notepad ++, I can create the class with javac Oi.java, but when I put java Hi, the following error appears:

  

"Error: Can not find or load the main Hi class"

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

Here are the links below the folder, notepad, prompt, and test running normally on Netbeans:

    
asked by anonymous 31.05.2018 / 18:33

1 answer

2

You're probably trying to run the class without compiling. You must compile the .java file before:

javac Oi.java

then run:

java Oi

See, the class is working normally:

  

Note:Makesurethattheclasshasthesamefilename,iftheclassiscalledMinhaClasse,thefileshouldalsobecalledMinhaClasse.java.

Inprint,yourfileisnamedHi.java,buttheclasssignatureiswithadifferentname(publicclassOie)

  

Obs2:Ifyouhavepackageinformationintheclass,thecompilerwilllookforthesefolders,andasyouwillnotfinditwillgivethiserror.Removethepackageinformationunlessyouhaveafolderhierarchyofthepackage.

Alsotrywiththecommandbelow,wherejvmwillforcetheclasspathasthecurrentfolderandlookfortheclassjustinsideit:

java-cp.Oi

In this answer and in this other SOEn has more detailed explanations of the reasons that can cause this problem.

    
31.05.2018 / 18:49