Welcome to Dream.In.Code
Become a Java Expert!

Join 150,038 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 1,583 people online right now. Registration is fast and FREE... Join Now!




java.lang.ClassNotFoundException

 
Reply to this topicStart new topic

java.lang.ClassNotFoundException, yes... this topic again

gl3thr0
4 Jun, 2008 - 05:44 AM
Post #1

D.I.C Head
**

Joined: 27 Oct, 2007
Posts: 209



Thanked: 3 times
My Contributions
When i go to run a java file from the command line i get the following error:

Exception in thread "main" java.lang.NoClassDefFoundError: Try2
Caused by: java.lang.ClassNotFoundException: Try2
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:276)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)

be4 i had this problem but with the javac command.. bt now javac works fine bt typing "java" causes the these errors tongue.gif
java -version works though so im guessing it has something to do with the classpath or path variables?

my runtime environment is located here
C:\Program Files\Java\jre1.6.turn.gif6

nd the JDK
C:\Program Files\Java\jdk1.6.turn.gif6

if you no wt the classpath and/or path variables should be set to can u just post it? thanks

when i was looking this up i came across a new variable "JAVA_HOME" is this something i should set?
User is offlineProfile CardPM
+Quote Post

1lacca
RE: Java.lang.ClassNotFoundException
4 Jun, 2008 - 06:17 AM
Post #2

code.rascal
Group Icon

Joined: 11 Aug, 2005
Posts: 3,822



Thanked: 12 times
My Contributions
Please post what command line you use to run javac, java, from where, and where are your class and java files are located.
User is offlineProfile CardPM
+Quote Post

gl3thr0
RE: Java.lang.ClassNotFoundException
4 Jun, 2008 - 08:11 AM
Post #3

D.I.C Head
**

Joined: 27 Oct, 2007
Posts: 209



Thanked: 3 times
My Contributions
QUOTE(1lacca @ 4 Jun, 2008 - 07:17 AM) *

Please post what command line you use to run javac, java, from where, and where are your class and java files are located.


i was just using command prompt on a windows xp on a school computer. at home it works fine.

i wrote a simple HelloWorld(Try2.java) program and saved it 2 the c drive
opened up command prompt
typed cd \
then javac Try2.java
it compiled fine ( i tested by running the class in eclipse)

however when i typed java Try2
i got the java.lang.NoClassDefFoundError:



the other really weird thing that happens is, the first time u use a command (java, javac) in a shell it takes forevvver 2 respond (5ish mins) seems like its searching for the file or something. it goes back to normal speed after though..
ie:
win+r
cmd
C:\>java -veresion
(wait 5 min)
java version ...
Java™ SE Runtime Environment (build...
Java HotSpot™ Client VM (build....


C:\>java -version
(instantly)
java version ...
Java™ SE Runtime Environment (build...
Java HotSpot™ Client VM (build....
C:\>exit

This post has been edited by gl3thr0: 4 Jun, 2008 - 08:13 AM
User is offlineProfile CardPM
+Quote Post

cutegrrl
RE: Java.lang.ClassNotFoundException
4 Jun, 2008 - 03:32 PM
Post #4

D.I.C Head
**

Joined: 12 May, 2008
Posts: 72



Thanked: 7 times
My Contributions
Start > Control Panel > System > Advanced Tab > Click on Environment Variables. Under user variables, click on the PATH entry and click edit. To the end of the variable value, add a semicolon and then the following: C:\Program Files\Java\jdk1.6.0_xx\bin

Don't replace the entire existing value. The "_xx" part above refers to Update version.. Replace the "_xx" with the appropriate number of your Java JDK version.

In the lower table, System variables, select the variable CLASSPATH and press Edit. If you don't see a variable with that name, you don't need to set your CLASSPATH. Otherwise, to the end of the variable value, add a semicolon and then a period. Don't replace the entire existing value.


User is offlineProfile CardPM
+Quote Post

pbl
RE: Java.lang.ClassNotFoundException
4 Jun, 2008 - 03:57 PM
Post #5

D.I.C Lover
Group Icon

Joined: 6 Mar, 2008
Posts: 3,587



Thanked: 233 times
Dream Kudos: 75
My Contributions
Please post the output of DIR (if on Windows) ls (if on Unix/Linus) of the directory where you do your compile/run
User is online!Profile CardPM
+Quote Post

fsloke
RE: Java.lang.ClassNotFoundException
4 Jun, 2008 - 08:44 PM
Post #6

D.I.C Regular
***

Joined: 19 Dec, 2007
Posts: 258



Thanked: 4 times
My Contributions
I think this error is because of the javac cannot find the class file....

I assume you already run

javac Try2.java

Then you will get Try2.class

try run this....

java -classpath . Try2

You will see the result.....

User is offlineProfile CardPM
+Quote Post

gl3thr0
RE: Java.lang.ClassNotFoundException
5 Jun, 2008 - 07:44 AM
Post #7

D.I.C Head
**

Joined: 27 Oct, 2007
Posts: 209



Thanked: 3 times
My Contributions
k thanks. ill try it out in two days (weekend now)

i did try cutegrrl suggestion but it didnt fix anything.. (you said to change the use variable PATH.. it didnt exist so i created it. bt there was a path variable in under the system set?)

im beginning to wonder if this might have something 2do with the way the schools server is set up? is a problem on EVERY machine that has java. i just hadnt noticed cuz eclipse takes care of all this for u.
User is offlineProfile CardPM
+Quote Post

pbl
RE: Java.lang.ClassNotFoundException
5 Jun, 2008 - 01:02 PM
Post #8

D.I.C Lover
Group Icon

Joined: 6 Mar, 2008
Posts: 3,587



Thanked: 233 times
Dream Kudos: 75
My Contributions
QUOTE(gl3thr0 @ 5 Jun, 2008 - 08:44 AM) *

cuz eclipse takes care of all this for u.

So use the same as your Eclipse...
+- Window
+--- Preferences
+------- Installed JRE

chances are that JRE and JDK are around the same location

User is online!Profile CardPM
+Quote Post

gl3thr0
RE: Java.lang.ClassNotFoundException
5 Jun, 2008 - 02:02 PM
Post #9

D.I.C Head
**

Joined: 27 Oct, 2007
Posts: 209



Thanked: 3 times
My Contributions
QUOTE(pbl @ 5 Jun, 2008 - 02:02 PM) *

QUOTE(gl3thr0 @ 5 Jun, 2008 - 08:44 AM) *

cuz eclipse takes care of all this for u.

So use the same as your Eclipse...
+- Window
+--- Preferences
+------- Installed JRE

chances are that JRE and JDK are around the same location



they are. but the problem is i cant seem to get the enviroment variables set right. its a real pain cuz i cnt bring class files to school and run them . instead i have to import them into eclipse and right a new class to start them. i looked it up and it all seem 2 come down 2 either the CLASPATH or PATH variable.bt everywhere i look ppl have it set up differently... very frustrating tongue.gif
User is offlineProfile CardPM
+Quote Post

pbl
RE: Java.lang.ClassNotFoundException
5 Jun, 2008 - 02:12 PM
Post #10

D.I.C Lover
Group Icon

Joined: 6 Mar, 2008
Posts: 3,587



Thanked: 233 times
Dream Kudos: 75
My Contributions
QUOTE(gl3thr0 @ 5 Jun, 2008 - 03:02 PM) *

[they are. but the problem is i cant seem to get the enviroment variables set right. its a real pain cuz i cnt bring class files to school and run them . instead i have to import them into eclipse and right a new class to start them. i looked it up and it all seem 2 come down 2 either the CLASPATH or PATH variable.bt everywhere i look ppl have it set up differently... very frustrating tongue.gif

Can't believe it
Just open Window Explorer and do a search for javac.exe starting for c:\
you'll find it

User is online!Profile CardPM
+Quote Post

fsloke
RE: Java.lang.ClassNotFoundException
6 Jun, 2008 - 01:50 AM
Post #11

D.I.C Regular
***

Joined: 19 Dec, 2007
Posts: 258



Thanked: 4 times
My Contributions
normally you can found the javac.exe in the

C:\Program Files\JAVA\

in this folder you will saw the jdk1.6.XX version

Pls set the environment

example:
C:\Program Files\Java\jdk1.6.turn.gif4\bin

in order to run in command prompt...

=============================================

When you install elipse or Netbean, please install the jdk first then the software....

elipse or netbean will automatically set the JAVA path for you...
User is offlineProfile CardPM
+Quote Post

gl3thr0
RE: Java.lang.ClassNotFoundException
6 Jun, 2008 - 03:18 AM
Post #12

D.I.C Head
**

Joined: 27 Oct, 2007
Posts: 209



Thanked: 3 times
My Contributions
my runtime environment is located here

C:\Program Files\Java\jre1.6. _6

and the JDK
C:\Program Files\Java\jdk1.6. _6
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/8/09 09:48PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month