This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread 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 OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Run Time error" Watch "Run Time error" New topic
Author

Run Time error

Jeff Te
Greenhorn

Joined: Aug 11, 2009
Posts: 18
I have compiled my program into bytecode, and am having difficulty running the jvm. when i tried to run it i got the following error:

Exception in thread "main" java.lang.NoClassDefFoundError: Party
Caused by: java.lang.ClassNotFoundException: Party

Any help would be great...thanks!
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18765
    
  40

It can't find the class -- which could mean that your classpath isn't set correctly, or you put the class file in the wrong location.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Jeff Te
Greenhorn

Joined: Aug 11, 2009
Posts: 18
The class file is located here:

C:\Users\Jeff\Documents

My class path is set to:

C:\Users\Jeff\Documents\Java\jdk1.6.0_14\bin

abhishek kunal
Ranch Hand

Joined: Jul 27, 2009
Posts: 42
try this command

java -cp C:\Users\Jeff\Documents party


it should work
Jeff Te
Greenhorn

Joined: Aug 11, 2009
Posts: 18
Still no luck
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18765
    
  40

Jeff Te wrote:The class file is located here:

C:\Users\Jeff\Documents

My class path is set to:

C:\Users\Jeff\Documents\Java\jdk1.6.0_14\bin



First, there is a distinction between PATH and CLASSPATH. You need to tell us what was set and to what.

Second, the classpath is for the root of the classes. You also need to tell us if your classes are in packages.

And of course, you need to tell us exactly what is being executed -- the exact command line.

Henry
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11256
    
  16

Jeff Te wrote:The class file is located here:

C:\Users\Jeff\Documents

My class path is set to:

C:\Users\Jeff\Documents\Java\jdk1.6.0_14\bin


Note: There is no such thing as a "class path". you should have a "classpath" variable, a "path" variable, or possibly both... but "class path" is meaningless.


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

Joined: Aug 11, 2009
Posts: 18
i have a CLASSPATH as well as a path and both variables are set to the following:

C:\Users\Jeff\Documents\Java\jdk1.6.0_14\bin
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18765
    
  40

Jeff Te wrote:i have a CLASSPATH as well as a path and both variables are set to the following:

C:\Users\Jeff\Documents\Java\jdk1.6.0_14\bin


That is the problem. CLASSPATH is for classes, not for the jvm and compiler. Unset it.

[edit: accidentally reverse PATH and CLASSPATH... fixed]

Henry
Jeff Te
Greenhorn

Joined: Aug 11, 2009
Posts: 18
i unset it, but it still gives me the same error
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18765
    
  40

Jeff Te wrote:i unset it, but it still gives me the same error


See my previous post, you need to tell us a bunch of other stuff, or we can't tell you what's wrong.

Henry
abhishek kunal
Ranch Hand

Joined: Jul 27, 2009
Posts: 42
@henry,, no we can append our own path in the classpath variable for extra classes we have...
abhishek kunal
Ranch Hand

Joined: Jul 27, 2009
Posts: 42
can you please show the code??
Jeff Te
Greenhorn

Joined: Aug 11, 2009
Posts: 18
PATH is set to

C:\Users\Jeff\Documents\Java\jdk1.6.0_14\bin

I'm not sure if my classes are in packages, how could I tell this?

My command line looks like this:

C:\Users\Jeff\Documents> java Party

(The class file is Party.class, saved in C:\Users\Jeff\Documents)
abhishek kunal
Ranch Hand

Joined: Jul 27, 2009
Posts: 42
look into the source file and tell if there is a package statement ?? if yes then remove that...have you coded this java file on your own??
Jeff Te
Greenhorn

Joined: Aug 11, 2009
Posts: 18
i tried 2 different programs:
ExampleProgram

//A Very Simple Example
class ExampleProgram {
public static void main(String[] args){
System.out.println("I'm a Simple Program");
}
}

as well as
Party

import java.awt.*;

import java.awt.event.*;

class Party {

public void buildinvite() {
Frame f = new Frame();
Label l = new Label("Party at Tim's");
Button b = new Button("You bet");
Button c = new Button("Shoot me");
Panel p = new Panel();
p.add(l);
} // more code here...
abhishek kunal
Ranch Hand

Joined: Jul 27, 2009
Posts: 42
type this command java ExampleProgram , the name of class in which you have main function......
abhishek kunal
Ranch Hand

Joined: Jul 27, 2009
Posts: 42
suppose you are having main method in a class named class2 then the command should be

java class2
Jeff Te
Greenhorn

Joined: Aug 11, 2009
Posts: 18
The ExampleProgram ran...thanks for all of your help!
Party still won't but I may have a code error in there...
abhishek kunal
Ranch Hand

Joined: Jul 27, 2009
Posts: 42
you are welcome dude!!
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11256
    
  16

Jeff Te wrote:The ExampleProgram ran...thanks for all of your help!
Party still won't but I may have a code error in there...

If you have a code error, then either it won't compile, or something bad would happen when you ran it. a code error wouldn't stop the program from running.

Make sure you have a file called Party.class

cd to the directory where it is.

run this:

java Party

and tell us what happens.
Jeff Te
Greenhorn

Joined: Aug 11, 2009
Posts: 18
I tried, still got the following error:

Exception in thread "main" java.lang.UnsupportedClassVersionError: Party : Unsupported major.minor version 8242.8224
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18765
    
  40

Jeff Te wrote:I tried, still got the following error:

Exception in thread "main" java.lang.UnsupportedClassVersionError: Party : Unsupported major.minor version 8242.8224


Can you tell us what version of the compiler you are using? Or if you are using any special class loaders? I have never seen those major and minor numbers before.

Henry
Jeff Te
Greenhorn

Joined: Aug 11, 2009
Posts: 18
I'm using the JavaFX1.2 SDK
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38513
    
  23
Not the J2SE Version? Write javac -version and java -version at the command line and see whether you get anything beginning with 1.6.0. You can download the ordinary JDK here.
abhishek kunal
Ranch Hand

Joined: Jul 27, 2009
Posts: 42
you need to reinstall the normal jdk...not javafx one....install jdk1.6...problem is of version mismatch...
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14117
    
  16

Jeff Te wrote:I tried, still got the following error:

Exception in thread "main" java.lang.UnsupportedClassVersionError: Party : Unsupported major.minor version 8242.8224

This looks really strange. Normally this error means that you are trying to run a class compiled with a newer JDK on an older JRE. But this looks different, because the version number in the error message is very strange "8242.8224".

It looks like the class file is corrupted. Did you maybe save your source code with the extension ".class" instead of ".java", or did you do anything else that could have corrupted the class file?

Delete the class file, compile your source code and try to run it again.


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

Joined: Aug 11, 2009
Posts: 18
I saved the source file as .java before I compiled it. Would removing my Java completely and reinstalling it be a good idea?
krishna bala
Ranch Hand

Joined: Jul 20, 2009
Posts: 61
ciao , can you please tell em , which version java you used to compile the your java class and which version of java you used to run the java class ?
Jeff Te
Greenhorn

Joined: Aug 11, 2009
Posts: 18
I downloaded the JavaFX SDK...here is the link:

http://java.sun.com/javafx/1/reference/sdk-install/install-javafx-sdk-1-2.html
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Run Time error