Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP 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
Pie
Posts: 15438
41
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: 12185
34
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: 21405
84
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
Pie
Posts: 15438
41
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
Pie
Posts: 49776
69
  • 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