954,173 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Following tutorials 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
Newbie Poster
13 posts since Dec 2004
Reputation Points: 10
Solved Threads: 0
 

nm if i use java Motorcycle in command line it works just fine..

Diod
Newbie Poster
13 posts since Dec 2004
Reputation Points: 10
Solved Threads: 0
 

did you set your classpath?

how to set your classpath on xp
http://www.cs.ucsb.edu/~teliot/Path_and_Classpath.htm

paradox814
Posting Whiz
351 posts since Oct 2004
Reputation Points: 13
Solved Threads: 4
 

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

Diod
Newbie Poster
13 posts since Dec 2004
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You