Running java.class
- isapiens
- Fame ! Where are the chicks?!
- Posts: 533
- Joined: 05 May 2006, 16:00
- 18
- Location: Turn around
Running java.class
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?
- bad_brain
- Site Owner
- Posts: 11638
- Joined: 06 Apr 2005, 16:00
- 19
- Location: In your eye floaters.
- Contact:
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...
- 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
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
it brings back some memories. I wish you copied the code you wrote and let us review it..
DNR
-
He gives wisdom to the wise and knowledge to the discerning. He reveals deep and hidden things; he knows what lies in Darkness, and Light dwells with him.
He gives wisdom to the wise and knowledge to the discerning. He reveals deep and hidden things; he knows what lies in Darkness, and Light dwells with him.
- sternbildchen
- Fame ! Where are the chicks?!
- Posts: 421
- Joined: 26 Apr 2006, 16:00
- 18
- Location: Germany
- isapiens
- Fame ! Where are the chicks?!
- Posts: 533
- Joined: 05 May 2006, 16:00
- 18
- Location: Turn around
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...
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...
- bad_brain
- Site Owner
- Posts: 11638
- Joined: 06 Apr 2005, 16:00
- 19
- Location: In your eye floaters.
- Contact:
allright, here´s the classic version:
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.
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!");
}
}
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.
Last edited by bad_brain on 14 May 2006, 14:27, edited 1 time in total.
- bad_brain
- Site Owner
- Posts: 11638
- Joined: 06 Apr 2005, 16:00
- 19
- Location: In your eye floaters.
- Contact:
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...
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...