First of all, if you come across an error like this in Eclipse, you probably imported some project from your *workspace*
or anywhere else in your Windows
or you’ve tampered with the default settings of Eclipse
.
If you imported a project, check in the folder (open through explorer
) and realize that you have a file with the name .classpath
, open the file with an editor (Notepad
, for example). Note that there will be a variable like this:
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
Possibly if you changed version of Eclipse
, this variable may change, causing the error message cited for not finding the JRE’s "default" Eclipse
. This error can be fixed by creating a new Java project in Eclipse itself, and after that importing your project by unchecking the files .project
and .classpath
.
If you encountered this problem while trying to compile a code manually through the prompt de comandos do Windows (CMD)
environment variables are likely to be poorly configured and JDK (Java Development Kit) or JRE (Java Runtime) are incorrect.
In this case, check if you have created a JAVA_HOME type variable, and then set the path of your path as the same value JDK
, in my case the default folder of JDK
is:
C: Program Files Java jdk1.8.0_20
This variable serves as the programming language variables we use, the JAVA_HOME will store the default path of my JAVA language compilation package.
After that, check the environment variable CLASSPATH
holds the value:
.;%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
This clear that the operating system will change the value of the variable JAVA_HOME
by the way of his JDK
standard within the Windows
, that is to say, C:\Program Files\Java\jdk1.8.0_20
.
Another important observation is that if you embed your code via CMD
, always remember to compile in the correct order the classes, ie if the ClasseA
urge to ClasseB
, to ClasseB
should be compiled first, and ClasseA
next.
This way, it is also important to check if you are using package
(folders), because if you do not indicate the build path of the files in the command, your bitecodes
(files with extension .class
) default will be inside the folder itself that is compiling the code. So, if you build the ClasseA
that belongs to the pacote A
, and it uses the ClasseB
that belongs to the pacote B
, you must own this folder structure, compile the ClasseB
within a pacote B
(put the file ClasseB.class
inside the briefcase pacote B
), then compile the ClasseA
within a pacote A
(put the file ClasseA.class
inside the briefcase pacote A
). In that case the ClasseA
is the main one, so you run the file from bitecode
from her ($ java ClasseA
)
If you don’t, the compiler won’t be able to see the other folders, causing errors like "Couldn’t find class XXXXX".
Checked if you placed the input method
public static void main(String... args)
?– ptkato