| Forums.Sureshkumar.net : A Perfect Place to Share Knowledge Blogs Games Magazines |
|
|
#1 (permalink) |
|
Junior Member
Join Date: Jul 2007
Posts: 22
Thanks: 0 Thanked 0 Times in 0 Posts Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 2
|
exception in thread main
Hi everyone,
Recently i hav been facing this problem iam able to compile a java class and iam getting the .class file also but wen iam running it,it gives error saying "Exception in thread "main" java.lang.noClassDefFoundError:Test " where Test is my class name. all my environment settings are done(path and classpath in environment varible). waitng for ur replies. Thank u. |
|
|
|
|
|
#3 (permalink) |
|
Senior Member
Join Date: Oct 2006
Location: Mayiladurai (TN)
Posts: 225
Thanks: 8 Thanked 4 Times in 4 Posts Thanks: 8
Thanked 4 Times in 4 Posts
Rep Power: 4
|
Re: exception in thread main
Your can be solved by following
1) set path variable to the bin folder of java i.e if u install java on d: then set path as d:\java\jdk5.0\bin; 2) set classpath variable to the folder you want to store your class files i.e If u wish to store ur files on d:\Javaprgms set classpath as d:\javaprgms; Note : Your java file is also in the same folder and u also have to compile it on the same folder so that the corresponding class file is stored in that folder 3) confirm environment variables by the command java -version It shows the version of JAva and other details If it still results in error check ur code |
|
|
|
|
|
#4 (permalink) |
|
Junior Member
Join Date: Jul 2007
Posts: 22
Thanks: 0 Thanked 0 Times in 0 Posts Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 2
|
Re: exception in thread main
iam not able to run a simple java program also,(hello world prog),previously i made many prograns and got the result,but suddenly it is giving this exception,
import java.lang.*; class Test { public static void main(String aa[]) { System.out.println("Testing Success"); } } and for environment variable settings: path : .;C:\Program Files\Java\jdk1.5.0_02\bin; classpath : .;C:\Program Files\Java\jdk1.5.0_02\jre\lib\rt.jar;C:\Program Files\Apache Software Foundation\Tomcat 5.0\common\lib\servlet-api.jar; and my servlet programs are running well ,i only cant run core java applications. plzz help me out.i tried many ways but in vain. waitng for ur replies,Thank u. |
|
|
|
|
|
#5 (permalink) |
|
Senior Member
Join Date: Oct 2006
Location: Mayiladurai (TN)
Posts: 225
Thanks: 8 Thanked 4 Times in 4 Posts Thanks: 8
Thanked 4 Times in 4 Posts
Rep Power: 4
|
Re: exception in thread main
You path is set to bin folder thats correct
but classpath doesn't set to any specific folder and i think you are storing and compile on a specific folder thats why the exception occurs so Javalang Try this Create a folder say MyJavaPrograms in any drive say d: set classpath=d:\MyJavaPrograms; Then type ur program and save in MyJavaPrograms folder compile the file on the same folder i.e d:\MyJavaPrograms\javac Test.java Now run it will definetly work |
|
|
|
|
|
#6 (permalink) |
|
Junior Member
Join Date: Jul 2007
Posts: 22
Thanks: 0 Thanked 0 Times in 0 Posts Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 2
|
Re: exception in thread main
Hii TAM,sorry i dont know ur name,but iam afraid that u are wrong.classpath is always set to C:\Program Files\Java\jdk1.5.0_02\jre\lib\rt.jar; by this it is ensured that u can run ur java application from anywhere not as u mentioned from specifc folder.
u try this and chk it will work,try to set ur classpath as i mentioned and then u can write ur java programs from any folder u want on any drive. as rt.jar contains all the packages. try this and see it will definetly work.as far as my problem is ,i dont understand y it is not working it MUST work,as it was working earlier but suddenly it stopped working. i think its not the classpath problem ,and i also tried ur method which is also giving me the same error. Thank U,waitng for ur reply. |
|
|
|
|
|
#7 (permalink) |
|
Senior Member
Join Date: Oct 2006
Location: Mayiladurai (TN)
Posts: 225
Thanks: 8 Thanked 4 Times in 4 Posts Thanks: 8
Thanked 4 Times in 4 Posts
Rep Power: 4
|
Re: exception in thread main
Ok javalang as far as i know there is no need to mention the java run time library as classpath because the JVM first checks it for the class that are specified in your program. If ths class doesn't present in the runtime library then it looks for the base directory i.e jdk5.0/bin;. If the class is doesn't found here it searches the class files in the folder that u set in the classpath. Thats why I specify that to specify the specific folder as class path. I previously suffered similar kind of problem and it is solved by the method I mentioned before. Don't be afraid to pinpoint the mistakes because "No one is Master in this world" Thank u for comts
|
|
|
|
|
|
#8 (permalink) |
|
Moderator
Join Date: Apr 2006
Location: India
Posts: 636
Thanks: 57 Thanked 74 Times in 60 Posts Thanks: 57
Thanked 74 Times in 60 Posts
Rep Power: 17
|
Re: exception in thread main
r u sure ur rt.jar is in the specified location, anyway what TAM told is right, u dont need to specify rt.jar in the classpath ,jus u specify it till the lib folder thats it, try this out and u'll get a solution, if u install java, it would in the following location as far as i know c:\j2sdk1.5.0_02\lib, whatever the path u specified is related to runtime environment, but u have give the API path as the class path
Usually when u install JAVA in ur system, there will be two folder created in your system Ex: if u install J2sdk1.4.0 , the path will be like this C:\Program Files\Java\j2re1.4.2\lib
__________________
M0h@n |
|
|
|
|
|
#9 (permalink) |
|
Moderator
Join Date: Apr 2006
Location: India
Posts: 636
Thanks: 57 Thanked 74 Times in 60 Posts Thanks: 57
Thanked 74 Times in 60 Posts
Rep Power: 17
|
Re: exception in thread main
r u sure ur rt.jar is in the specified location, anyway what TAM told is right, u dont need to specify rt.jar in the classpath ,jus u specify it till the lib folder thats it, try this out and u'll get a solution, if u install java, it would in the following location as far as i know c:\j2sdk1.5.0_02\lib, whatever the path u specified is related to runtime environment, but u have to give the API location as the class path
Usually when u install JAVA in ur system, there will be two folder created in your system Ex: if u install J2sdk1.4.0 , the path will be like this C:\Program Files\Java\j2re1.4.2\lib -- this will be used by Java Runtime Environment and the Operating System, as far as i know, rt.jar provides a runtime environment. c:\j2sdk1.4.2\ will be ur directory for ur usage, like setting the path to the bin directory, setting the classpath for ur lib directory etc etc can be done from this directory U have to specify the second folder only in ur classpath Let me know your questions Thank You
__________________
M0h@n Last edited by t_mohan; 10-07-07 at 12:35 PM. |
|
|
|
|
|
#10 (permalink) |
|
Junior Member
Join Date: Oct 2007
Age: 25
Posts: 14
Thanks: 2 Thanked 0 Times in 0 Posts Thanks: 2
Thanked 0 Times in 0 Posts
Rep Power: 1
|
Re: exception in thread main
Hay Javalang,
I am new to this forum. When I was going thru all the posted questions, I saw ur post. So, is your problem of running a simple program solved? If solved, let me know how was it done? I tried ur code in my system with different ways. I got the exception "NoClassDefFoundError" when i tried to run the program with the command java Test.java. Let me know ur comments. Bye. |
|
|
|
|
|
#11 (permalink) |
|
Junior Member
Join Date: Jul 2007
Posts: 22
Thanks: 0 Thanked 0 Times in 0 Posts Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 2
|
Re: exception in thread main
Hii Raghu,
Iam really sorry but i dont remeber the solution,actually i was having the problem due to oracle.problem of java versions,as oracle has its own jvm and sets itself by default in th path settings.so wen we run the program it gives error like some "minor major .....".i dont remeber the error but we can rectify it by removing the jvm frm the oracle classpath. |
|
|
|
|
|
#12 (permalink) |
|
Senior Member
Join Date: Oct 2006
Location: Mayiladurai (TN)
Posts: 225
Thanks: 8 Thanked 4 Times in 4 Posts Thanks: 8
Thanked 4 Times in 4 Posts
Rep Power: 4
|
Re: exception in thread main
Raghu,
I think the error has been occurred because u execute with the command java Test.java We have to use .java extension only to compile a java file. After compilation it results the corresponding class Here it is Test.class Now you to execute it with the command java Test Now JVM correctly finds the class file Test.class and execute it |
|
|
|
|
|
#13 (permalink) |
|
Junior Member
Join Date: Oct 2007
Age: 25
Posts: 14
Thanks: 2 Thanked 0 Times in 0 Posts Thanks: 2
Thanked 0 Times in 0 Posts
Rep Power: 1
|
Re: exception in thread main
Hai TAM,
What u said is right but just i was trying to get that specific error saying "Exception in thread "main" java.lang.noClassDefFoundError:Test." The above error came when I tried to execute the program with 'java Test.java'. If I execute the program with 'java Test' then output will come. |
|
|
|
|
|
#14 (permalink) |
|
Junior Member
Join Date: Jul 2008
Posts: 3
Thanks: 0 Thanked 0 Times in 0 Posts Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 1
|
Re: exception in thread main
hi..........java lang i'm a biginner can u tell me the step by step process of running servlet ..........and what installation need for that.........
|
|
|
|
|
|
#15 (permalink) |
|
Junior Member
Join Date: Jul 2007
Posts: 22
Thanks: 0 Thanked 0 Times in 0 Posts Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 2
|
Re: exception in thread main
Hi Sushma,
For simple servlet program you need the following 1) first u need Apache Tomcat server (i recommend) 2) update ur CLASSPATH variable with the path of servlet-api.jar (better to keep servlet-api.jar in WEB-INF/lib folder of ur application) 3) every web application has a specfic directory structure to be followed , i hope u know the directory structure to be followed. 4)after writng the servlet code ,compile the file to get .class file which needs to be kept in classes directory (WEB-INF/classes )of ur application. 5)for running the application you need to hav your appication in webapps folder of tomcat(or you can have the war file of ur application) 6)from tomcat console you can run the application. this is very abstract view of the whole process , i hope senior members of the community will give you a more detailed and easier approach for your problem. if you are confused you can always post it. |
|
|
|
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | Rate This Thread |