• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Exception in thread main

 
Ranch Hand
Posts: 633
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 633
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you sir.
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,add "CLASSPATH=." into your profile,try again!
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"Vinoth SU", please check your private messages for an important administrative matter.
 
Campbell Ritchie
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

pr mdf wrote:


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