Java编程思想第4版中的一个例子, 为何不能运行?
执行时一直挂在那,没输出。PS D:\java\source> javac annotations/AtUnitExample1.java
PS D:\java\source> java annotations/AtUnitExample1
//: annotations/AtUnitExample1.java
package annotations;
import net.mindview.atunit.*;
import net.mindview.util.*;public class AtUnitExample1 {
public String methodOne() {
return "This is methodOne";
}
public int methodTwo() {
System.out.println("This is methodTwo");
return 2;
}
@Test boolean methodOneTest() {
return methodOne().equals("This is methodOne");
}
@Test boolean m2() { return methodTwo() == 2; }
@Test private boolean m3() { return true; }
// Shows output for failure:
@Test boolean failureTest() { return false; }
@Test boolean anotherDisappointment() { return false; }
public static void main(String[] args) throws Exception {
OSExecute.command(
"java net.mindview.atunit.AtUnit AtUnitExample1");
}
} /* Output:
annotations.AtUnitExample1
. methodOneTest
. m2 This is methodTwo . m3
. failureTest (failed)
. anotherDisappointment (failed)
(5 tests)>>> 2 FAILURES <<<
annotations.AtUnitExample1: failureTest
annotations.AtUnitExample1: anotherDisappointment
*///:~
执行时一直挂在那,没输出。PS D:\java\source> javac annotations/AtUnitExample1.java
PS D:\java\source> java annotations/AtUnitExample1
//: annotations/AtUnitExample1.java
package annotations;
import net.mindview.atunit.*;
import net.mindview.util.*;public class AtUnitExample1 {
public String methodOne() {
return "This is methodOne";
}
public int methodTwo() {
System.out.println("This is methodTwo");
return 2;
}
@Test boolean methodOneTest() {
return methodOne().equals("This is methodOne");
}
@Test boolean m2() { return methodTwo() == 2; }
@Test private boolean m3() { return true; }
// Shows output for failure:
@Test boolean failureTest() { return false; }
@Test boolean anotherDisappointment() { return false; }
public static void main(String[] args) throws Exception {
OSExecute.command(
"java net.mindview.atunit.AtUnit AtUnitExample1");
}
} /* Output:
annotations.AtUnitExample1
. methodOneTest
. m2 This is methodTwo . m3
. failureTest (failed)
. anotherDisappointment (failed)
(5 tests)>>> 2 FAILURES <<<
annotations.AtUnitExample1: failureTest
annotations.AtUnitExample1: anotherDisappointment
*///:~
解决方案 »
- 怎样替换字符串
- 为什么设置了jdbc connector的路径,拷到了jre下面,java程序还是无法连接到数据库?谢谢各位大虾了
- 事件监听处理问题,求教
- 刚弄一个程序,竟然出错了,想来想去就是不明白(数据库方面的问题)
- 小妹刚学java 照书上抄的代码怎么会有NullPointerException呢
- 谁有JAVA入门经典这本书的源代码
- 请问如何知道这panel中的一个component有焦点啊.?
- 关于jb使用的问题
- 各位高手,请问在Tomcat下怎么解决中文问题?
- Java 1.3有没有类似 MSDN 的电子帮助文档,介绍Java的类库的用法!有的话,哪儿可以Down!(高分求解)
- 关于字体设置
- 字节数组转成指定编码的字符串的问题
不过现在本人已经解决了,在这里说一下。这个程序要用到作者个人的包,在程序的开头已有说明:
import net.mindview.atunit.*;
import net.mindview.util.*;
把这些包放在执行工作路径下,这个应该不是问题,我遇到问题时这些都做过。解决问题是这下面:
1. 编译用到的类: PS D:\java\source> javac net\mindview\atunit\AtUnit.java
2. 在annotations/AtUnitExample1.java程序中的main()方法的内容改一下,也就是类名AtUnitExample1加上路径:
OSExecute.command("java net.mindview.atunit.AtUnit annotations/AtUnitExample1");我还没想明白为什么第2步是必要的。
现在是学基本的东西,简单的程序,用IDE感觉更复杂了,还得学IDE。想了很长时间都没法解决才到这来求助的,还好,后来解决了。
不然出错的话很难找的。