Friday, July 31, 2009

Problem In executing java program?

Hi i hav problem in runing java program actually when i type a program in notepad and save to as java file .when a try to compile it using javac it get compile the class file is also created but when i try to run using java command in cmd it shows error msg like this


Exception in thread "main" java.lang.NoclassDefFound error c:\Hello ..


pls help me out..


this is just sample code......non of java file run on my pc i m


using jsdk1.5.0_08 version

Problem In executing java program?
Are you sure that your whole java progra is written in class and also class file is constructed after compilation. If yes problem may be the compiled class file may created in different directory. So try to run the program in the directory where your class file is reside.
Reply:This occurs when .class is not found.





Are you using package statement at top?





for eg:





package com.abc ;


class xyz{


}





say this file is in "SampleProgram" directory


for compiling you need to be at "abc" folder level


to run you should be at "SampleProgram" level.
Reply:Did you set your CLASSPATH variable?





This is required for Java VM to fetch the appropriate JDK libraries. Check out this discussion thread for more info:





http://forum.java.sun.com/thread.jspa?th...
Reply:check this answer first in the link .... i have answer to the same question before





http://in.answers.yahoo.com/question/ind...








Create your own environment variables for quick folder navigation








1. Right-click the "My Computer" icon (Computer in Vista)


2. Choose "Properties" from the context menu


3. Click the "Advanced" tab ("Advanced system settings" link in Vista)


4. Click the "Environment Variables" button


5. Under the "User variables" section, click new


6. Enter the hotstring in the "Variable name" field and the path in the "Variable value" field


7. Click OK


No comments:

Post a Comment