DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   Java (http://www.daniweb.com/forums/forum9.html)
-   -   Following tutorials and getting java.lang.NoClassDefFoundError (http://www.daniweb.com/forums/thread16186.html)

Diod Dec 29th, 2004 8:12 am
Reading a book and getting java.lang.NoClassDefFoundError
 
Im reading a book on java, and im on the lesson OOP and java.

This is my code:
class Motorcycle {
String make;
String color;
boolean engineState;

void startEngine() {
if (engineState == true)
System.out.println("The engine is already on.");
else {
engineState = true;
System.out.println("The engine is now on.");
}
}

void showAtts() {
System.out.println("This motorcycle is a " + color + " " + make);
if (engineState == true)
System.out.println("The engine is on.");
else System.out.println("The engine is off.");
}

public static void main(String[] args) {
Motorcycle m = new Motorcycle();
m.make = "Yamaha RZ350";
m.color = "yellow";
System.out.println("Calling showAtts...");
m.showAtts();
System.out.println("--------");
System.out.println("Starting engine...");
m.startEngine();
System.out.println("--------");
System.out.println("Calling showAtts...");
m.showAtts();
System.out.println("--------");
System.out.println("Starting engine...");
m.startEngine();
}
}

This is the error i get:
java.lang.NoClassDefFoundError: Motorcycle/Motorcycle (wrong name: Motorcycle)
        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"

Diod Dec 29th, 2004 4:22 pm
Re: Following tutorials and getting java.lang.NoClassDefFoundError
 
nm if i use java Motorcycle in command line it works just fine..

paradox814 Dec 30th, 2004 5:00 am
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

Diod Dec 30th, 2004 6:41 am
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


All times are GMT -4. The time now is 6:30 am.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC