aspose file tools*
The moose likes Beginning Java and the fly likes Exception in thread main Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Exception in thread main" Watch "Exception in thread main" New topic
Author

Exception in thread main

Pramod P Deore
Ranch Hand

Joined: Jul 15, 2008
Posts: 629

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


Life is easy because we write the source code.....
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42639
    
  65
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.


Ping & DNS - my free Android networking tools app
krmgroups
Greenhorn

Joined: Mar 28, 2008
Posts: 6
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

Joined: Jul 15, 2008
Posts: 629

Thank you sir.
Kevin lee
Greenhorn

Joined: Sep 20, 2007
Posts: 5
Hi,add "CLASSPATH=." into your profile,try again!
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39877
    
  28
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

Joined: Oct 13, 2005
Posts: 39877
    
  28
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

Joined: Oct 13, 2005
Posts: 39877
    
  28
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

Joined: Mar 28, 2008
Posts: 6
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

Joined: Jan 10, 2002
Posts: 61658
    
  67

"Vinoth SU", please check your private messages for an important administrative matter.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39877
    
  28
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

Joined: Mar 27, 2009
Posts: 12
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

Joined: Jul 26, 2007
Posts: 10523
    
    9

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.


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10523
    
    9

pr mdf wrote:

Please check your private messages for an important administrative matter.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Exception in thread main