这是《Java编程思想》(第三版)上的一个例子,编译时没有错误,运行时它总是报这样一个错误:
java.lang.NoClassDefFoundError: bruceeckel/simpletest/Test
at c03.Assignment. <clinit> (Assignment.java:14)
Exception in thread "main "
不知道是什么原因,“static Test monitor = new Test();”这个语句总是有问题。
package c03;
//: c03:Assignment.java
// Assignment with objects is a bit tricky.
// From 'Thinking in Java, 3rd ed. ' (c) Bruce Eckel 2002
// www.BruceEckel.com. See copyright notice in CopyRight.txt.
import com.bruceeckel.simpletest.*;
class Number {
int i;
}
public class Assignment {
static Test monitor = new Test();
public static void main(String[] args) {
Number n1 = new Number();
Number n2 = new Number();
n1.i = 9;
n2.i = 47;
System.out.println( "1: n1.i: " + n1.i +
", n2.i: " + n2.i);
n1 = n2;
System.out.println( "2: n1.i: " + n1.i +
", n2.i: " + n2.i);
n1.i = 27;
System.out.println( "3: n1.i: " + n1.i +
", n2.i: " + n2.i);
monitor.expect(new String[] {
"1: n1.i: 9, n2.i: 47 ",
"2: n1.i: 47, n2.i: 47 ",
"3: n1.i: 27, n2.i: 27 "
});
}
} ///:~
------解决方案--------------------
你的classpath的问题,没有Test这个类
------解决方案--------------------
import com.bruceeckel.simpletest 有问题吧 你系统里面确定有这几个文件夹?