Status
Not open for further replies.

~Phenom~

The No.1 Stupid
hi friends ,
i m new to java and faced the following problem while running my first program


class First
{ public static void main(String args[])
{ System.out.println("welcome");
}
}

i have saved this program as First.java in bin directory

it gets compiled successfully with command javac First.java on command prompt but when i run this using java First it gives error saying
exception in thread "main" java.lang.NoclassDefFoundError:First

please help me , tell me where is the problem? n how to solve it?
 

Manojap

Broken In
The java problem

You have to try this while compiling and running

javac first.java

then u have made the mistake.. may be u type class file name as small letter

try this
java First[do not use the .class extention]

U can find usefull java turorial on my blog take look and give me feed back

*www.sourcecode-india.blogspot.com

Manoj A.P ,G-Tec Computer Education
 

icecoolz

Cyborg Agent
Re: The java problem

Manojap said:
You have to try this while compiling and running

javac first.java

then u have made the mistake.. may be u type class file name as small letter

Thats incorrect. How he compiled it is right. Java is case sensitive and hence he has specified the right.

Phenom:

Your problem is that although your class compiles it is not available for the java execuatable to execute. By this I mean that the .class file which gets generated would need to be in the classpath. The easiest way to do this would be to execute this command in the DOS window:

set CLASSPATH=.;%CLASSPATH%

What the above command does is to set the class path to the current directory and all sub directories. This setting will be available to this current window only. Which is useful if you move around directories a lot. Now run your java file:

java First

and it sould work.

Hope this helps. If you need any further help let me know and I'll see what I can do.
 
OP
~Phenom~

~Phenom~

The No.1 Stupid
thanx icecoolz
set CLASSPATH=.;%CLASSPATH%
worked
problem solved
thank u very much .
u must be a java genius coz i asked the same prob to all my teachers , colleagues ,etc. but no one could answer the sol.
i was so frustrated that i thought there is some problem in my PC and was about to format it and reinstall windows XP.
but thanx to you , u brought my smile back.
thank u.
 

icecoolz

Cyborg Agent
lol...I aint no java genius. I just went thru the same pains which you did altho I did it seven years back :) And yea after being in the java field if I dont even know this then .... ;) Gald to help mate.
 
Status
Not open for further replies.
Top Bottom