This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Beginning Java and the fly likes run time error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "run time error" Watch "run time error" New topic
Author

run time error

pammi rao
Greenhorn

Joined: Feb 24, 2010
Posts: 7
when i compile the program it works fine but when i run the program the following errors are displayed

Exception in thread"main" java.lang.noclassdeffounderror:example
caused by: java.lang.classNotFoundException:example
at java.net.URLClassloader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(NAtive method)
at java.net.URLClassloader.loadclass(unknown source)
at sun.misc.Launcher$appClassLoader.loadclass(Unkown csource)
Could not find main class:example .Program will exit.

please help
this is the exact same error irrespective of which program i try to run
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14114
    
  16

Welcome to JavaRanch.

Did you compile your program before you're trying to run it?
Is your class really named "example"? (Note, Java is case-sensitive, don't type "example" if it's really named "Example")
Do you have a file "example.class" in the current directory?
What command are you typing exactly to run your program?
Did you set your classpath? If yes, then unset it (you do generally not need to set classpath).

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
pammi rao
Greenhorn

Joined: Feb 24, 2010
Posts: 7
the name is right .when i compile it the compiler does not show any error .the class path was not set i set it later but it still gives me the error.this error is persistent irrespective of the program i try to run . Have tried everything i can think of .
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11250
    
  16

Do you have a file somewhere named "example.class"?


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
pammi rao
Greenhorn

Joined: Feb 24, 2010
Posts: 7
yeah that was the first thing i checked . its in the same folder where the programs are stored
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18753
    
  40


1. Is the class in a package? Meaning is there a "package" statement near the top of the source file?

2. Do you happen to have a CLASSPATH variable set?

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14114
    
  16

pammi rao wrote:the class path was not set i set it later but it still gives me the error.

Make sure you have no CLASSPATH set - not having a CLASSPATH set will make Java look in the current directory for the example.class file.
Siva Arun
Greenhorn

Joined: Feb 23, 2010
Posts: 28
Try Something like


"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan.
Priya dharshini
Ranch Hand

Joined: Aug 06, 2005
Posts: 78
Your java class file is compiled by latest java version and you are trying to run by using older version of Java. Thats where you will get this error.

Check your jdk & jre versions.


Thanks & Regards,
Priyadharshini . T
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38441
    
  23
Priya dharshini wrote:Your java class file is compiled by latest java version and you are trying to run by using older version of Java.
No, it isn't. that would cause a different Error, probably this one.
 
wood burning stoves
 
subject: run time error