• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Exception in thread main

 
Pramod P Deore
Ranch Hand
Posts: 632
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello everybody!!!

I have type a simle program on Linux it's run, But when I tried the same program on windows it compiles but can not run it give me the following error please reply me.

Exception in thread "main" java.lang.NoClassDefFoundError: Test
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How are you trying to run the program? Is the current directory in the classpath? You'd have to use "java -classpath . Test" to achieve this.
 
krmgroups
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
past one time same error occured for me when i run java
it shown
Exception in thread "main" java.lang.NoClassDefFoundError:Test.
just set class path after compile the java appl.
like
d:set CLASSPATH=D:\
d:java test
your program should run...!
happy....
regard,
Vinu-Chennai
 
Pramod P Deore
Ranch Hand
Posts: 632
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you sir.
 
Kevin lee
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,add "CLASSPATH=." into your profile,try again!
 
Campbell Ritchie
Sheriff
Pie
Posts: 49367
62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That exception occurs if you don't have a file called Test.class accessible. Most common reason: navigating to the wrong folder.

You ought to have .; or ;. or ;.; in your CLASSPATH system environment variable on Windows and 99% or Windows installations have the . in there somewhere by default.
Did you have a package declaration in your Test.java class? (You probably didn't, but that would move the Test.class file into a different folder.)
Use the "dir" command to find whether you have got Test.class in the folder you have navigated to in the command prompt.

Use a similar technique to setting up the PATH to make sure there is a . in the CLASSPATH. There is probably a simpler way to view the CLASSPATH, maybe you write "classpath" but I can't remember what it is.

Hope you get your problem sorted soon
 
Campbell Ritchie
Sheriff
Pie
Posts: 49367
62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by myself:
That exception occurs if you don't have a file called Test.class accessible. . . .
It seems a silly question, but please confirm that your Test.java file compiled successfully.
 
Campbell Ritchie
Sheriff
Pie
Posts: 49367
62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh, I am sorry, I hadn't noticed you are on Linux; on Linux you don't need a CLASSPATH at all, as long as you have navigated your shell to the correct folder with the cd command.
 
krmgroups
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Exception in thread "main" java.lang.NoClassDefFoundError: HelloWorld

If you receive this error, java cannot find your compiled byte code file, HelloWorld.class.If both your class files and source code are in the same working directory and if you try running your program from the current working directory than, your program must get executed without any problems as, java tries to find your .class file is your current directory. If your class files are present in some other directory other than that of the java files we must set the CLASSPATH pointing to the directory that contain your compiled class files.CLASSPATH can be set as follows on a Windows machine:

a. Click Start > Right Click "My Computer" and click on "Properties"
b. Click Advanced > Environment Variables.
in the user variable->click new or edit then give variable name as CLASSPATH.and value as location of your .class file
eg.your class is in D' means give D:\

Add the location of classes´┐Ż folder containing all your java classes in User Variables.

If there are already some entries in the CLASSPATH variable then you must add a semicolon and then add the new value . The new class path takes effect in each new command prompt window you open after setting the CLASSPATH variable.
thats all...
Vinoth-KRm
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64959
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Vinoth SU", please check your private messages for an important administrative matter.
 
Campbell Ritchie
Sheriff
Pie
Posts: 49367
62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And your advice to alter the CLASSPATH on Windows is quite unnecessary. As long as there is .; ;. or ;.; in the CLASSPATH it will work. In fact you shouldn't normally change the system CLASSPATH at all.
 
netali joshef
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I get the class not found exception evrey time I try to run the even a simple hello wqorld program.Although my .class file got created i.e. It compiled the code succesfully but culd not run it.I have set classpath and other enevronment var proprly.I have neatbeans installed on my systems,Is that create a prolbem programmes running with the command prompt?/!!
I tried unstall and then reinstall too.
please help me out with the problwm, because I tired thinking about this strange thing.

Thanks & Regards
 
Maneesh Godbole
Saloon Keeper
Posts: 11064
13
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
krmgroups wrote:


The naming policy has already been brought to your notice multiple times before. It is strongly recommended that you take it seriously. You are expected to adjust your display name to comply to the naming policy before posting anything. Please note, this is not optional and naming violators stand a chance of getting their account suspended.
 
Maneesh Godbole
Saloon Keeper
Posts: 11064
13
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
pr mdf wrote:

Please check your private messages for an important administrative matter.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic