File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Not sure if this the place?? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Not sure if this the place??" Watch "Not sure if this the place??" New topic
Author

Not sure if this the place??

Steven Pierce
Greenhorn

Joined: May 27, 2004
Posts: 6
Good Morning,

I am trying to learn Java. I am new to programming so please excute me if I am in the wrong place. I am using the book head first java and I am on the first set of code to enter. There are some errors but that is a different issue.

import java.awt.*;
import java.awt.event.*;
class Party {
public void buildinvite(){
Frame f = new Frame();
Label i = new Label("Party at tim's");
Button b = new Button("You Bet");
Button c = new Button("shoot me");
Panel p = new Panel();
p.add(i);
}
}

I got this to finally compile. When I try to excute it, I get all of these errors. HELP...

java.lang.NoClassDefFoundError: lib/party (wrong name: Party)
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:537)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:123)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:251)
at java.net.URLClassLoader.access$100(URLClassLoader.java:55)
at java.net.URLClassLoader$1.run(URLClassLoader.java:194)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:187)
at java.lang.ClassLoader.loadClass(ClassLoader.java:289)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:274)
at java.lang.ClassLoader.loadClass(ClassLoader.java:235)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:302)
Exception in thread "main"

Thank you for any help that you can provide.
Carol Murphy
village idiot
Bartender

Joined: Mar 15, 2001
Posts: 1197
Stephen, this is a forum for those folks who are doing the cattle drive assignments. Check out the cattle drive, you might be interested in signing up!
I'm moving this post to the JavaInGeneral(Beginner) forum. Look for a response there.
Carol
[ May 28, 2004: Message edited by: Carol Murphy ]
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

There's just one error; all the lines are part of one message. It's called a "stack trace." The top line is the function where the error was found; each line below is the function that called the one above. It can be very useful while debugging. In this case, though, none of the lines are from code you wrote, so it's not very helpful at all.

In any case, the line

java.lang.NoClassDefFoundError: lib/party (wrong name: Party)

describes the actual error: Java tried to load the class lib.party (with a lower-case 'P'), found a file named party.class, looked in the file, and found a class lib.Party (with an upper case 'P'), decided there was a problem, and aborted. Java is case sensitive, even though Windows isn't (so Windows can't tell the difference between files named Party.class and party.class); if the class is named Party with a capital 'P', then you have to capitalize it when you run the program -- but it looks like you did not.


[Jess in Action][AskingGoodQuestions]
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11479
    
  16

Ernest wrote: a bunch of stuff

I was gonna say that!!!

And Steven, even if you do get 100 errors, don't ever panic. a lot of times one typo will cause a cascade of other errors. My advice would be just focus on the first one and fix it. Then re-compile, and see how many disappear. often you'll fix more than you would expect when you change one thing.

Keep asking questions!!! It's the best way to learn... and most people here are pretty friendly (and folks like Ernest are awful dang smart, too!!!)


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

Joined: May 27, 2004
Posts: 6
OK.. I went back and changed the class Party to a Cap "P". I then went back and did a new compile and started over. I am getting th same error.

import java.awt.*;
import java.awt.event.*;
class Party { //Note the change
public void buildinvite(){
Frame f = new Frame();
Label i = new Label("Party at tim's");
Button b = new Button("You Bet");
Button c = new Button("shoot me");
Panel p = new Panel();
p.add(i);
}
}


When I saved it this time, I did it with Party.java as instructed by the book and here. So what am I doing wrong??
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

It already was called Party in the file and in your original post. What I'm saying is that when you ran it, you typed "java party" and not "java Party".

Now, I'm also noticing that before you were saying "lib.party", and now you're not. The "lib" would indicate a Java package, but the class has no package statement in it. When you try to run this, your current directory should be the place where the Party.class file is, and you should type "java Party", with a capital 'P.'
Steven Pierce
Greenhorn

Joined: May 27, 2004
Posts: 6
OK.. I did do a java Party (Cap P) and it is still giving me
the same error. I know this is a really lam question, but when
I tried to get into the directory that it is in, j2sdk1.4.2_04
I am getting this is not a valid dir.

I have the Party.java in the root of C:\ and Party.class is there
also. When I run the javac it is done via the path statement.

C:\j2sdk1.4.2_04\bin\javac Party.java It is giving me a .class
file with the same name. When I do java Party I am getting :

C:\>j2sdk1.4.2_04\bin\javac.exe Party.java

C:\>j2sdk1.4.2_04\bin\java.exe Party
Exception in thread "main" java.lang.NoClassDefFoundError: Party
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
What happens if you try the following command?

java -classpath . Party


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
Note that the class Party that you've posted is not a program - it has no main method. So, once you overcome the NoClassDefFoundError, you'll discover another error.
Steven Pierce
Greenhorn

Joined: May 27, 2004
Posts: 6
Ok.. if I type the command
java -classpath . Party

Exception in thread "main" java.lang.NoSuchMethodError: main

I get this error. Now what I am using to write this was, the
program in the book Head Start Java. They show it running
with a pop up by just that code.

If you look on page 3 of the book, it will show what I have been
working on. At first when I read it, I thought that it was one
that was showing an example of what java code is. Now that
I look at it, I see that it does not have a main function.

Sorry to have troubled everyone. I guess I will move on in
the book..

Steven
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
That

java -classpath . Party

works for you, while

java Party

does not, indicates that your CLASSPATH is improperly configured. I highly recommend that you figure out configuring it to include the current working directory, specified by a period.

How the CLASSPATH is set depends on your operating system. Take a look at our FAQ on setting the CLASSPATH for instructions.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Not sure if this the place??