Win a copy of Securing DevOps this week in the Security forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

run time error  RSS feed

 
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
 
Java Cowboy
Sheriff
Posts: 16081
88
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 .
 
lowercase baba
Bartender
Posts: 12610
50
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
 
author
Sheriff
Posts: 23387
138
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
Sheriff
Posts: 16081
88
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.
 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try Something like
 
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.
 
Sheriff
Posts: 57882
178
  • 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.
 
Gravity is a harsh mistress. But this tiny ad is pretty easy to deal with:
Thread Boost - a very different sort of advertising
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!