madhire
asked on
Exception in thread "main" java.lang.NoClassDefFoundError
when i run the java program HelloWorldApp i am getting the error -Exception in thread "main" java.lang.NoClassDefFoundE rror , i am new to java and i downloaded java in C: directory and set user and system varaible to -
USER VARAIBLE:
%SystemRoot%\system32;%Sys temRoot%;% SystemRoot %\System32 \Wbem;C:\P rogram Files\Common Files\Ulead Systems\MPEG;C:\j2sdk1.4.2 _09\bin
SYSTEM VARAIBLE:
%SystemRoot%\system32;%Sys temRoot%;% SystemRoot %\System32 \Wbem;C:\P rogram Files\Common Files\Ulead Systems\MPEG;C:\j2sdk1.4.2 _09\bin
SET CLASSPATH:
C:j2sdk1.4.2_09\bin\;%CLAS SPATH%;
when i compile the programe there is no problem, i am seeing two files HelloWorldApp.java and helloWorldApp.class, when try this command-set CLASSPATH=, the prgrame is running and giveing result-HelloWorld.
the source code is:
/**
* The HelloWorldApp class implements an application that
* displays "Hello World!" to the standard output.
*/
public class HelloWorldApp {
public static void main(String[] args) {
// Display "Hello World!"
System.out.println("Hello World!");
}
}
pleasr response in urgent, i am wasting all my time to download diffrent versions.
USER VARAIBLE:
%SystemRoot%\system32;%Sys
SYSTEM VARAIBLE:
%SystemRoot%\system32;%Sys
SET CLASSPATH:
C:j2sdk1.4.2_09\bin\;%CLAS
when i compile the programe there is no problem, i am seeing two files HelloWorldApp.java and helloWorldApp.class, when try this command-set CLASSPATH=, the prgrame is running and giveing result-HelloWorld.
the source code is:
/**
* The HelloWorldApp class implements an application that
* displays "Hello World!" to the standard output.
*/
public class HelloWorldApp {
public static void main(String[] args) {
// Display "Hello World!"
System.out.println("Hello World!");
}
}
pleasr response in urgent, i am wasting all my time to download diffrent versions.
Setting classPath: Thouroughly read this: http://mindprod.com/jgloss/classpath.html
It contains some clear (Helloworld) examples
It contains some clear (Helloworld) examples
Assume your program exists in C:\work
then give CLASSPATH=%CLASSPATH%;C:\w ork;
then give CLASSPATH=%CLASSPATH%;C:\w
ASKER
hai dejanpazin
i removed set CLASSPATH from environmental varaibale but still i am getting the same error
i removed set CLASSPATH from environmental varaibale but still i am getting the same error
I quote from the link I provided:
To run a HelloWorld.class app in C:\MyDir, use:
cd \MyDir
java.exe -classpath . HelloWorld (HelloWorldApp, in your case)
To run a HelloWorld.class app in C:\MyDir, use:
cd \MyDir
java.exe -classpath . HelloWorld (HelloWorldApp, in your case)
ASKER
hai zzynx.
i am don't understand what you are saying....will you explain me in clear. i stored the java in C:\j2sdk1.4.2_09 version..
i am don't understand what you are saying....will you explain me in clear. i stored the java in C:\j2sdk1.4.2_09 version..
Try this
javac -classpath filename.java
javac -classpath filename.java
cd to the diurectory containing your class file (probably the one you compiled it from) and run it using:
java HelloWorld
java HelloWorld
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
>> when i compile the programe there is no problem, i am seeing two files HelloWorldApp.java and helloWorldApp.class,
Suppose you have those files in a directory C:\MyJavaApps
Then
1) Open a Cmd prompt
2) type
cd \MyJavaApps
3) type
java -classpath . HelloWorldApp
Suppose you have those files in a directory C:\MyJavaApps
Then
1) Open a Cmd prompt
2) type
cd \MyJavaApps
3) type
java -classpath . HelloWorldApp
ASKER
hai zzyx,
i stored file in C:\j2sdk.14.2_09
then i gave command in cmd prompt like- c:\j2sdk1.4.2_09\java-clas spath.Hell oWorldApp but i amgetting the following error
java-classpath.HelloWorldA pp' is not recognised as an internal or external comand
i stored file in C:\j2sdk.14.2_09
then i gave command in cmd prompt like- c:\j2sdk1.4.2_09\java-clas
java-classpath.HelloWorldA
sorry, above I meant
java HelloWorldApp
java HelloWorldApp
ASKER
hai dejanpazin ,
thanks for your suggestion, it's worked for me, i put classpath to empty then i restarted cmd prompt.
thanks
thanks for your suggestion, it's worked for me, i put classpath to empty then i restarted cmd prompt.
thanks
>> 3) type
>> java -classpath . HelloWorldApp
Exactly as posted
Including all the spaces
>> java -classpath . HelloWorldApp
Exactly as posted
Including all the spaces
>> i stored file in C:\j2sdk.14.2_09
Bad idea.
Better use a dedicated directory to store your source/class files in
Bad idea.
Better use a dedicated directory to store your source/class files in
We have a winner :-)
CLASSPATH must include the classes your programm uses. Since you only have a HelloWorldApp class, the CLASSPATH should include that class.
There is one special rule: if you dont set the CLASSPATH, then the folder from which you are running the application is by default in the classpath. Thats why your programm runs if you do this: set CLASSPATH=
But if you do this:
SET CLASSPATH:C:j2sdk1.4.2_09\
then your CLASSPATH is set, and it doesnt include the class you are trying to run.
Basicaly, the simple solution to your problem is: dont have the CLASSPATH set in your environment. Set it only when you need it.