这是Java编程思想上的一个例子,我在Eclipse中编译时没有错误,运行时弹出一个错误对话框“Java Virtual Machine Launcher”,里面内容是:
Could not find the main class. Program will exit.
同时在“Console”标签下,出现下面内容:
java.lang.NoClassDefFoundError: bruceeckel/simpletest/Test
at c03.Assignment.<clinit>(Assignment.java:14)
当点击完上面对话框的“确定”键后,“Console”标签下又增加了以下的内容:
Exception in thread "main"其中,Test类的确包含在我自己导入的com.jar的com.bruceeckel.simpletest包中。
只是我有点不明白的是,当我打开com.bruceeckel.simpletest包中Test.class文件后,在代码编辑窗口出现的是:
Source not found
The source attachment does not contain the source for the file Test.class.
You can change the source attachment by clicking Change Attached Source below:
“Change Attached Source...”
public class bruceeckel.simpletest.Test{
......//类成员和类方法定义,类方法只进行了定义和声明,没有给出具体实现。
}
而且,当我打开系统中的类库时,发现里面的.class文件也是这种形式。比如说,位于JRE System Library下的rt.jar文件中的java.lang包中的String.class文件,也是上面的那种形式。我不知道,为什么会出现这种情况,请哪位高手指导一下。原代码如下:
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"
});
}
} ///:~
Could not find the main class. Program will exit.
同时在“Console”标签下,出现下面内容:
java.lang.NoClassDefFoundError: bruceeckel/simpletest/Test
at c03.Assignment.<clinit>(Assignment.java:14)
当点击完上面对话框的“确定”键后,“Console”标签下又增加了以下的内容:
Exception in thread "main"其中,Test类的确包含在我自己导入的com.jar的com.bruceeckel.simpletest包中。
只是我有点不明白的是,当我打开com.bruceeckel.simpletest包中Test.class文件后,在代码编辑窗口出现的是:
Source not found
The source attachment does not contain the source for the file Test.class.
You can change the source attachment by clicking Change Attached Source below:
“Change Attached Source...”
public class bruceeckel.simpletest.Test{
......//类成员和类方法定义,类方法只进行了定义和声明,没有给出具体实现。
}
而且,当我打开系统中的类库时,发现里面的.class文件也是这种形式。比如说,位于JRE System Library下的rt.jar文件中的java.lang包中的String.class文件,也是上面的那种形式。我不知道,为什么会出现这种情况,请哪位高手指导一下。原代码如下:
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"
});
}
} ///:~
错误是类没有找到
你说你的TEST类在com.bruceeckel.simpletest
但你写的test的类名却是bruceeckel.simpletest.Test
而后的import却又有com了??
这什么跟什么啊....class文件是编译后的文件,用类浏览器只能看到方法声明,这没错
public class com.bruceeckel.simpletest.Test{
......//类成员和类方法定义,类方法只进行了定义和声明,没有给出具体实现。
}