944,142 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 12946
  • Java RSS
Dec 29th, 2004
0

Reading a book and getting java.lang.NoClassDefFoundError

Expand Post »
Im reading a book on java, and im on the lesson OOP and java.

This is my code:
Java Syntax (Toggle Plain Text)
  1. class Motorcycle {
  2. String make;
  3. String color;
  4. boolean engineState;
  5.  
  6. void startEngine() {
  7. if (engineState == true)
  8. System.out.println("The engine is already on.");
  9. else {
  10. engineState = true;
  11. System.out.println("The engine is now on.");
  12. }
  13. }
  14.  
  15. void showAtts() {
  16. System.out.println("This motorcycle is a " + color + " " + make);
  17. if (engineState == true)
  18. System.out.println("The engine is on.");
  19. else System.out.println("The engine is off.");
  20. }
  21.  
  22. public static void main(String[] args) {
  23. Motorcycle m = new Motorcycle();
  24. m.make = "Yamaha RZ350";
  25. m.color = "yellow";
  26. System.out.println("Calling showAtts...");
  27. m.showAtts();
  28. System.out.println("--------");
  29. System.out.println("Starting engine...");
  30. m.startEngine();
  31. System.out.println("--------");
  32. System.out.println("Calling showAtts...");
  33. m.showAtts();
  34. System.out.println("--------");
  35. System.out.println("Starting engine...");
  36. m.startEngine();
  37. }
  38. }

This is the error i get:
Java Syntax (Toggle Plain Text)
  1. java.lang.NoClassDefFoundError: Motorcycle/Motorcycle (wrong name: Motorcycle)
  2. at java.lang.ClassLoader.defineClass0(Native Method)
  3. at java.lang.ClassLoader.defineClass(ClassLoader.java:537)
  4. at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:123)
  5. at java.net.URLClassLoader.defineClass(URLClassLoader.java:251)
  6. at java.net.URLClassLoader.access$100(URLClassLoader.java:55)
  7. at java.net.URLClassLoader$1.run(URLClassLoader.java:194)
  8. at java.security.AccessController.doPrivileged(Native Method)
  9. at java.net.URLClassLoader.findClass(URLClassLoader.java:187)
  10. at java.lang.ClassLoader.loadClass(ClassLoader.java:289)
  11. at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:274)
  12. at java.lang.ClassLoader.loadClass(ClassLoader.java:235)
  13. at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:302)
  14. Exception in thread "main"
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Diod is offline Offline
13 posts
since Dec 2004
Dec 29th, 2004
0

Re: Following tutorials and getting java.lang.NoClassDefFoundError

nm if i use java Motorcycle in command line it works just fine..
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Diod is offline Offline
13 posts
since Dec 2004
Dec 30th, 2004
0

Re: Following tutorials and getting java.lang.NoClassDefFoundError

did you set your classpath?

how to set your classpath on xp
http://www.cs.ucsb.edu/~teliot/Path_and_Classpath.htm
Last edited by paradox814; Dec 30th, 2004 at 5:05 am. Reason: added url
Reputation Points: 13
Solved Threads: 4
Posting Whiz
paradox814 is offline Offline
351 posts
since Oct 2004
Dec 30th, 2004
0

Re: Following tutorials and getting java.lang.NoClassDefFoundError

Ok thx, just done that, gotta do a reboot

edit: no luck.. im gonna use JCreator LE(isnt the same as JBuilder), used it before and proved to work so.. thx for the help
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Diod is offline Offline
13 posts
since Dec 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: Printing Embedded Icons
Next Thread in Java Forum Timeline: accessing clent bios from the server





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC