Forums.Sureshkumar.net : A Perfect Place to Share Knowledge         Blogs     Games    Magazines

"Sharing knowledge does not lessen your store, often it gets you more. Sharing plays a key role in relationships and bonding, happens in small steps and is assisted through community membership."

Go Back   SURESHKUMAR.NET FORUMS > TECHNICAL DISCUSSIONS > JAVA Technologies
Register FAQ Members List Calendar Games Blogs Search Today's Posts Mark Forums Read

   

Reply
 
LinkBack Thread Tools Rate Thread Display Modes
Old 04-07-07, 05:37 PM   #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 JavaLang is on a distinguished road
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.
JavaLang is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 04-07-07, 07:03 PM   #2 (permalink)
Moderator
 
t_mohan's Avatar
 
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 t_mohan is a splendid one to behold t_mohan is a splendid one to behold t_mohan is a splendid one to behold t_mohan is a splendid one to behold t_mohan is a splendid one to behold t_mohan is a splendid one to behold t_mohan is a splendid one to behold
Re: exception in thread main

Hi,
Can u paste your code over here, i'll help u out
__________________
M0h@n
t_mohan is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 05-07-07, 11:16 AM   #3 (permalink)
TAM
Senior Member
 
TAM's Avatar
 
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 TAM is on a distinguished road
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
TAM is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 05-07-07, 11:27 AM   #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 JavaLang is on a distinguished road
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.
JavaLang is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 05-07-07, 11:40 AM   #5 (permalink)
TAM
Senior Member
 
TAM's Avatar
 
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 TAM is on a distinguished road
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
TAM is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 05-07-07, 11:57 AM   #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 JavaLang is on a distinguished road
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.
JavaLang is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 05-07-07, 12:20 PM   #7 (permalink)
TAM
Senior Member
 
TAM's Avatar
 
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 TAM is on a distinguished road
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
TAM is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 10-07-07, 10:58 AM   #8 (permalink)
Moderator
 
t_mohan's Avatar
 
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 t_mohan is a splendid one to behold t_mohan is a splendid one to behold t_mohan is a splendid one to behold t_mohan is a splendid one to behold t_mohan is a splendid one to behold t_mohan is a splendid one to behold t_mohan is a splendid one to behold
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
t_mohan is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 10-07-07, 10:58 AM   #9 (permalink)
Moderator
 
t_mohan's Avatar
 
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 t_mohan is a splendid one to behold t_mohan is a splendid one to behold t_mohan is a splendid one to behold t_mohan is a splendid one to behold t_mohan is a splendid one to behold t_mohan is a splendid one to behold t_mohan is a splendid one to behold
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.
t_mohan is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 10-10-07, 01:51 AM   #10 (permalink)
Junior Member
 
raghuvamshi_ece's Avatar
 
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 raghuvamshi_ece is on a distinguished road
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.
raghuvamshi_ece is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 10-10-07, 04:10 AM   #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 JavaLang is on a distinguished road
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.
JavaLang is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 10-10-07, 11:34 PM   #12 (permalink)
TAM
Senior Member
 
TAM's Avatar
 
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 TAM is on a distinguished road
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
TAM is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 11-10-07, 06:41 PM   #13 (permalink)
Junior Member
 
raghuvamshi_ece's Avatar
 
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 raghuvamshi_ece is on a distinguished road
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.
raghuvamshi_ece is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 04-07-08, 01:24 PM   #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 sushma singh is on a distinguished road
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.........
sushma singh is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 04-07-08, 03:12 PM   #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 JavaLang is on a distinguished road
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.
JavaLang is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes Rate This Thread
Rate This Thread: