Hi, I'm trying to start a class under eclipse that return en exception in
thread "main". I executed many codes without any broken message. How to fix
that ? Thanks in advance.
# The class :
//Polymorphisme 02
class Shape {
void draw() {}
void erase() {}
}
class Circle extends Shape {
void draw() {
System.out.println("Circle.draw()");
}
void erase() {
System.out.println("Circle.erase()");
}
}
class Square extends Shape {
void draw() {
System.out.println("Square.draw()");
}
void erase() {
System.out.println("Square.erase()");
}
}
class Triangle extends Shape {
void draw() {
System.out.println("Triangle.draw()");
}
void erase() {
System.out.println("Triangle.erase()");
}
}
public class Shapes {
public static Shape randShape() {
switch((int) (Math.random()*3)) {
default:
case 0: return new Circle();
case 1: return new Square();
case 2: return new Triangle();
}
}
public static void main(String[] args) {
Shape[] s=new Shape[9];
//Remplissage du tableau avec des formes [shapes]:
for (int i= 0; i<s.length;i++)
s[i]=randShape();
//Appel polymorphe des méthodes
for(int i=0;i<s.length;i++)
s[i].draw();
}
}
# In the console :
java.lang.NoClassDefFoundError: shape (wrong name: Shape)
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
Exception in thread "main"
Duane Evenson - 27 May 2006 13:17 GMT
> Hi, I'm trying to start a class under eclipse that return en exception in
> thread "main". I executed many codes without any broken message. How to fix
[quoted text clipped - 99 lines]
>
> Exception in thread "main"
The trouble is with your setup of java.
Try this as a test:
Go to the directory where Shapes.class and Shape.class exist.
Run "java -cp . Shapes".
The program should now run.
The fix involves your $CLASS_PATH variable
You need to either delete your $CLASS_PATH environmental variable or, if
it points to important libraries, add your current working directories to
the path.
Good luck,
Duane
Chris Uppal - 28 May 2006 11:44 GMT
> public class Shapes {
[...]
> public static void main(String[] args) {
[...]
> # In the console :
> java.lang.NoClassDefFoundError: shape (wrong name: Shape)
Perhaps you have (by mistake) told Eclipse to start in class Shape, rather than
in class Shapes.
-- chris