• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Not sure if this the place??

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
village idiot
Posts: 1208
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!!!)
 
Steven Pierce
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What happens if you try the following command?

java -classpath . Party
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic