This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

run time error

 
pammi rao
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15207
36
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
pammi rao
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12086
29
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you have a file somewhere named "example.class"?
 
pammi rao
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yeah that was the first thing i checked . its in the same folder where the programs are stored
 
Henry Wong
author
Marshal
Pie
Posts: 20894
76
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15207
36
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try Something like
 
Priya dharshini
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Campbell Ritchie
Sheriff
Posts: 48424
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic