Page 1 of 1
Running java.class
Posted: 13 May 2006, 19:39
by isapiens
Hi, i wrote the 'Hello World' in java (just started programing..). Anyway, i managed to compile it successfully, but now i cant run the program. I am using cmd to do it, but everytime i run it i get this message : ""Exception in thread "main" java.lang.NoClassDefFoundError" I am sure its a noob error. My .class file is in the same directory as java.exe. It said something about set 'CLASSPATH= java HelloWorld' on internet but that didnt help it. What am i doing wrong?
Posted: 14 May 2006, 06:56
by bad_brain
well, can have different reasons....
- PATH variable not set properly (make sure the path to the
bin-folder of Java is in the PATH variable of the environment variables)
- start the app with
java appname, not with
java appname.class, pretty common beginner-error.
- wrong class name (make sure the class-file has the same name as announced in the source, if the class in the source is called "class x" and the file is called "y.class" it will not work)
- a simple mistake in writing, Java is a little annyoing because the error messages can be very confusing, you can post the source here and we will have a look at it...
Goodbye Cruel World
Posted: 14 May 2006, 09:21
by DNR
I can't believe I just heard "Hello World" programming
it brings back some memories. I wish you copied the code you wrote and let us review it..
DNR
Posted: 14 May 2006, 10:00
by sternbildchen
I had the same Problem with the Dos console.^^
Now i downloaded JCreator LE and it works much better for me
Posted: 14 May 2006, 12:02
by isapiens
Well this is wierd. I am following the instructions on this web site <url>
http://java.sun.com/docs/books/tutorial ... .html</url> they seem pretty straightforward but it still doesnt work. Here is what i do: set CLASSPATH= C:\...\bin after that i type java HelloWorld but it still gives me the error.
I assume the problem is in the set variable. I successully ran the program as an applet in HTML.
btw this HelloWorld programm is slightly different then the classical one. You see i am reading the "JAva for dummies", it pretty usefull for a beginner but i hate how they treat you as a moron. And they always have to be special, here is their HelloWorld code
<pre>
import java.applet.*;
import java.awt.*;
/*
* HelloWorld
* @version 0.1
* @author
dkoosis@isc.com
*/
public class HelloWorld extends Applet {
Label helloLabel = new Label ("Yo, you lookin' at me?");
public void init() {
setBackground(Color.yellow);
add (helloLabel);
}
}
</pre>
Anyway if fixing this isnt worth it i can alwas get a java editor or smth...
Posted: 14 May 2006, 13:59
by bad_brain
allright, here´s the classic version:
Code: Select all
class Hello_World {
//you have to call the main method, except in applets
public static void main(String args[]) {
System.out.println("Hello world!");
}
}
copy and compile it, it will work....
the code you posted is an applet, and so only can run in appletviewer or in a HTML document. running it in command prompt can not work because it uses graphical elements (that´s why it imports the awt-package), so you can´t start it with
java name, you have to use
appletviewer name instead.
Posted: 14 May 2006, 14:17
by isapiens
Well that explains it... Stupid book, they used GUI... I should have guessed. Thanks for help. I think i am just gonna continue using HTMl to see if my programms work.
Posted: 14 May 2006, 14:39
by bad_brain
np....
as long as you will code applets it´s fine to embed it in html....I find it pretty strange they begin with GUIs...normally the main-method is the first thing you learn because any command line-app needs it (at least you should know it from the start, what it means is already a little more advanced), followed by variables and loops...
....if you need help again simply post...