• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Error Messages...

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I feel like I have no clue what I am doing! I just installed what I think is the Java server for programming in Java, but I don't know if I have or not. It made its own enviromental variable on my computer :

C:\Sun\AppServer\bin;C:\j2sdk1.4.2_08\bin

I run the compiler and it works, but whenever I run it it does not work and I always have to put C where the file is located at) after java in DOS prompt. I thought you could just write ...

I am also getting this error message when I run it correctly for example The error is:

Exception in thread "main" java.lang.NoClassDefFoundError C:\Java\HelloWorld.java

Can anyone tell me the reason behind this?
Rat
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"Raistin", welcome to JavaRanch. It looks like you may have overlooked our display name policy when you signed up. Your name falls in the category of "obviously fictitious"; please change it. Thank you.
 
Aaron Woodland
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Okay, name changed...
 
Jim Yingst
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks. It sounds like you need to set the classpath, either by setting the system variable CLASSPATH or by using the -classpath flag (which can be shortened to -cp):

java -cp . HelloWorld

The dot means that the classpath is set to the current directory, the some one that HelloWorld.java and HelloWorld.class are in.
 
Aaron Woodland
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I did as you said and set a class path variable for the two directories...

C:\Java
C:\Documents and Settings\Kevin\My Documents\Java Programs
I am still getting the same error message though.
 
Sheriff
Posts: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You also need to make sure that the PATH includes the path to javac.exe (probably something like
PATH=C:\j2sdk1.4.2_08\bin;%PATH%
Then, as long as you are sitting in the same directory as the source file (for example the file is here:
C:\java\SourceFile.java
and you are here:
C:\Java>),
you can just type
javac SourceFile.java
otherwise you need to type
javac C:\(full path to the source file)\SourceFile.java
[ August 09, 2005: Message edited by: Marilyn de Queiroz ]
 
Jim Yingst
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It sounds like the javac step is working, and calling java you're at least getting a NoClassDefinitionFoundError. That tells us that the system is able to find the javac.exe and java.exe files in the PATH.

So, your source file is apparently at

    C:\Java\HelloWorld.java

correct? After you compile with javac, is there a .class file at

    C:\Java\HelloWorld.class ?

If not, where is it? What directory are you actually in?

Note also that when you try to run with java, you do not include the .java or .class extension to the filename. Just include the name of the class.

If none of the above helps, then I would guess that the CLASSPATH is still wrong. What, exactly, is it set to? You can get this info on Windows with

    echo %CLASSPATH%
 
Ranch Hand
Posts: 531
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
IMO the short cuts and use of CLASSPATH do nothing but confuse the new user.

Forget about packages and third-party jars and start with a basic Hello.java that outputs Hello.class and you want to run that.

First type in foobar and hit enter. That's what you will see if either java or javac is not installed or not in your path. I assume they are because it is automatically done by the installer.

Now, tell the compiler where to put the output as follows. We will use spaces in path names requiring quotes.

javac -d "/some folder/some where" Hello.java

OK, now let's run it and tell java where the class can be found:

java -classpath "/some folder/some where" Hello

In this case "class" is assumed.

Here's a more complicated example where the source file is not in the current directory:

javac -d "/some folder/some where" "/acme/rocket engines/Hello.java"

Javac doesn't care where the source is, 'long as you tell it. You know where the class is because you specified it explicitly.
 
Aaron Woodland
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here is what shows up in the Enviromental variables under PATH:

C:\Sun\AppServer\bin;C:\j2sdk1.4.2_08\bin

Here is what is under CLASSPATH:

C:\Java,C:\Documents and Settings\Kevin\My Documents\Java Programs

After I did compile my HelloWorld program I did get a .CLASS file in the directory where I kept my source file which is located at C:\Java... It is still getting the same error after I have ran the program even after making sure everything is correct... I also feel like I have a ton of Java stuff installed also...

Raistlin
 
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are so close! Just turn that comma in your classpath (right after C:\Java) into a semi-colon and you should be good to go.

As an aside, you don't need Sun's app server unless you want to develop and test JSPs, Servlets, EJB's etc. For the "regular stuff", the JDK is all you need (the stuff that's in the C:\j2sdk1.4.2_08\bin).
 
Aaron Woodland
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
After adding the semi colon between C:\Java,C:\Documents and Settings\Kevin\My Documents\Java Programsand getting rid of C:\Sun\AppServer\bin, so it wil show this:

PATH:
C:\j2sdk1.4.2_08\bin

CLASSPATH:
C:\Java;C:\Documents and Settings\Kevin\My Documents\Java Programs

After inserting in the following:



It still has an error message which is :

error: cannot read: HelloWorld.java
1 error


After compiling it like I used to do which is :



It compiles the .java file after inserting this code into it.

After compiling it I type in



I get the same error message as before...

Exception in thread "main" java.lang.NoClassDefFoundError

C:\Java\HelloWorld.java


Might I also include I have the compiler Netbeans, Jcreator, and Eclipse... I also have the folowing Java files:
j2sdk-1_4_2_08-windows-i586-p
j2eesdk-1_4_01_2005Q1-windows
jdk-1_5_0_04-windows-i586-p
and probably a few others....

Might I also add that the code I am compiling is just the simple HelloWorld application:

Raistlin
[ August 10, 2005: Message edited by: Aaron Woodland ]
 
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Aaron Woodland:

After compiling it I type in




Almost there, try just

java HelloWorld
 
Marilyn de Queiroz
Sheriff
Posts: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator








Just wanted to verify that you are sitting in the C:\Java directory while you're typing all these commands.
[ August 10, 2005: Message edited by: Marilyn de Queiroz ]
 
Kristin Stromberg
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hmmm. After you changed your classpath, did you open a new command window to run your java stuff? If so and it's still not working, try adding "." to your classpath (without the quotes, and preceded by a semi-colon).
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Marilyn de Queiroz:
Just wanted to verify that you are sitting in the C:\Java directory while you're typing all these commands.

[ August 10, 2005: Message edited by: Marilyn de Queiroz ][/QB]



Shouldn't matter as c:\java is (assuming nothing has changed from earlier posts) in his classpath
 
Marilyn de Queiroz
Sheriff
Posts: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Originally posted by Joanne Neal:
Shouldn't matter as c:\java is (assuming nothing has changed from earlier posts) in his classpath


Have you tried it?

C:\Program Files\Java\jdk1.5.0_03\bin>echo %classpath%
C:\Java;.;C:\tinkering\jr.jar;C:\j2sdkee1.3.1\lib\j2ee.jar;C:\apache-ant-1.6.1\lib\ant.jar;C:\junit3.8.1\junit.jar

C:\Program Files\Java\jdk1.5.0_03\bin>javac Dog.java
error: cannot read: Dog.java
1 error

C:\Program Files\Java\jdk1.5.0_03\bin>javac C:\Java\Dog.java

C:\Program Files\Java\jdk1.5.0_03\bin>
[ August 10, 2005: Message edited by: Marilyn de Queiroz ]
 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
when you run java you dont put the .java or .class at the end of the class... just the name of the Class...
 
Rick O'Shay
Ranch Hand
Posts: 531
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
After you changed your classpath, did you open a new command window to run your java stuff

Alternatively he could not ignore the best practice of not using CLASSPATH as shown in my example. Funny thing is that had the procedure I outlined been followed none of these issues would still be present and he would have a general solution to compiling and running anything from anywhere. Oh well, no way like the hard way I suppose.
 
Marilyn de Queiroz
Sheriff
Posts: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Rick O'Shay:
Funny thing is that had the procedure I outlined been followed none of these issues would still be present and he would have a general solution to compiling and running anything from anywhere.



Not true, Rick.

C:\Program Files\Java\jdk1.5.0_03\bin>javac -d C:\Java Dog.java
error: cannot read: Dog.java
1 error

But:
C:\Program Files\Java\jdk1.5.0_03\bin>javac -d C:\Java C:\Java\Dog.java
works.

Also,
C:\Java>javac Dog.java
works just fine
[ August 10, 2005: Message edited by: Marilyn de Queiroz ]
 
Aaron Woodland
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am so confused... lol I am pretty new at DOS prompt also... So what do I need to do to run the program?
Rat
 
Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Holy crap. No offence, but this is supposed to be easier? He's obviously learning and you're throwing a whole mess of crap at him.

What happened to going to:

set the path (directions at sun's site)
open notepad and write code
open command prompt
navigate to the folder you have your .java file in that you just wrote ( cd c:\javastuff )
compile: javac filename.java
run: java filename

the guy's trying to do HelloWorld. Why the hell would he confuse life with a CLASSPATH?

(just reread that. didn't mean to sound like an ass. it just came out that way)
 
Marilyn de Queiroz
Sheriff
Posts: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What happened to going to:

set the path (directions at sun's site)


Seems like his path is good. (seems like his classpath is good now too)

open notepad and write code

Seems like his code is good.

open command prompt
navigate to the folder you have your .java file in that you just wrote ( cd c:\javastuff )

This is what I keep asking. Haven't got an answer yet.

compile: javac filename.java
run: java filename


Yep.
[ August 10, 2005: Message edited by: Marilyn de Queiroz ]
 
Aaron Woodland
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
LoL... Thanks for the information Fielder. I got the program running.
Rat
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Marilyn de Queiroz:
Originally posted by Joanne Neal:
Shouldn't matter as c:\java is (assuming nothing has changed from earlier posts) in his classpath


Have you tried it?



I agree it won't work for compiling, but it was running the program that the OP was having problems with and
will work from any directory if c:\java is in the classpath. I guess I should have made it clearer that that was what I was referring to.
 
Marilyn de Queiroz
Sheriff
Posts: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Aaron Woodland:
LoL... Thanks for the information Fielder. I got the program running.
Rat


I'm glad to hear that.
 
Aaron Woodland
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I just want to thanks for everyone elses help to. I actually had no clue about this website till I started reading "Head First Java"!
Thanks,
Rat
 
a wee bit from the empire
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic