Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

error with my first program

i downloaded the j2sdk-1_4_2_11-nb-5_0-win set it up on my pc am runnin winXP am learnin from how java how to program 5th edition but i keep gettin this error when i try to run the simple welcome prog.
"Exception in thread "main" java.lang.NoClassDefFoundError: welcome/java"
if any one can help plz do it
[314 byte] By [lizard0o] at [2007-11-11 9:43:20]
# 1 Re: error with my first program
The interpreter is looking for a class called "welcome/java" which is supported in the "main" method of your class and cannot find it. Sounds as if there is a typo in your class file.
nspils at 2007-11-11 22:32:40 >
# 2 Re: error with my first program
the book didnt tell me to make any classes here is the code am tryin to run
public class welcome1

{

public static void main( String args [])

{

System.out.println("welcome to java programming");

}

}
lizard0o at 2007-11-11 22:33:41 >
# 3 Re: error with my first program
How are you executing your program? (in NetBeans or at the command prompt?)
nspils at 2007-11-11 22:34:33 >
# 4 Re: error with my first program
command prompt
lizard0o at 2007-11-11 22:35:39 >
# 5 Re: error with my first program
i used the javac command after settin the path and classpath and i get that error
welcome.java:1: class welcome1 is public, should be declared in a file named wel
come1.java
public class welcome1
^
1 error
am i missin somethin?
lizard0o at 2007-11-11 22:36:43 >
# 6 Re: error with my first program
No, that is absolutely correct. The name of the java file should be the name of the class.
nspils at 2007-11-11 22:37:42 >
# 7 Re: error with my first program
then wuts wrong lizard0o_1@hotmail.com add me plz we can talk there so i can get wut am missin
lizard0o at 2007-11-11 22:38:46 >
# 8 Re: error with my first program
is your java code file named welcome1.java? The compiler doesn't think so.
nspils at 2007-11-11 22:39:44 >
# 9 Re: error with my first program
no my file named welcome.java not welcome1 and the command i use in cmd is java welcome.java or javac welcome.java
lizard0o at 2007-11-11 22:40:42 >
# 10 Re: error with my first program
Then either change the name of the file to welcome1.java, or change the line in your code

public class welcome1

to

public class welcome
nspils at 2007-11-11 22:41:48 >
# 11 Re: error with my first program
thanx alot for ur help but still havin a prob i changed the file name to welcome1 when i call command javac welcome1.java it created a welcome1.class file but no out put on the screen and when i call the java welcome1.java i get the first error

F:\sana 4\start my java\welcome>javac welcome1.java

F:\sana 4\start my java\welcome>java welcome1.java
Exception in thread "main" java.lang.NoClassDefFoundError: welcome1/java
wut do u think it is this time
lizard0o at 2007-11-11 22:42:46 >
# 12 Re: error with my first program
When you invoke the java interpreter (java ... ) the command is "java welcome1" - you are "executing" the welcome1.class file produced by the compiler.

The compiler, if there are no error messages or warnings, just returns the command prompt. So what you are seeing is the expected outcome of the compilation of a properly formed program.

So, now try to run the compiled code by typing

java welcome1

at the command prompt.
nspils at 2007-11-11 22:43:49 >
# 13 Re: error with my first program
it worked at last my first code in java run with no errors lol thanx alot
lizard0o at 2007-11-11 22:44:45 >
# 14 Re: error with my first program
And, I trust, far from the last code you will run in java with no errors. Good luck in your exploration of the language!
nspils at 2007-11-11 22:45:51 >