2011-10-07 19 views
2

我想使用MonkeyRunner生成MotionEvent(從屏幕觸摸)。我已閱讀 http://developer.android.com/guide/developing/tools/monkeyrunner_concepts.html的信息。NoClassDefFoundError:com/google/common/base /在Jython中導入MonkeyRunner時的謂詞

的問題是,這個方案的Jython:

from com.android.monkeyrunner import MonkeyRunner 

if __name__ == '__main__': 
    # Connects to the current device, returning a MonkeyDevice object 
    device = MonkeyRunner.waitForConnection() 

執行時,我得到了以下錯誤:

Traceback (most recent call last): 
    File "C:\Documents and Settings\jjungb00\python\workspace\monkey\src\runner.py",  line 6, in <module> 
    from com.android.monkeyrunner import MonkeyRunner 
java.lang.NoClassDefFoundError: com/google/common/base/Predicate 

at com.android.monkeyrunner.MonkeyRunner.classDictInit(MonkeyRunner.java:48) 

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 

at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) 

at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) 

at java.lang.reflect.Method.invoke(Unknown Source) 

at org.python.core.PyJavaType.init(PyJavaType.java:534) 

at org.python.core.PyType.createType(PyType.java:1264) 

at org.python.core.PyType.addFromClass(PyType.java:1201) 

at org.python.core.PyType.fromClass(PyType.java:1291) 

... 跳過一些堆棧跟蹤 ...

Caused by: java.lang.ClassNotFoundException: com.google.common.base.Predicate 

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) 

...

我已經從android sdk工具/ lib中添加monkeyrunner.jar作爲外部庫。 我使用jython 2.5.2在XP上運行。

不知道該怎麼辦?我想我必須添加另一個庫,但我不知道在哪裏或哪個。

回答

8

您需要添加Google Collections庫 - 目前重命名爲Guava。在android SDK目錄中查找guavalib.jar。

+0

謝謝你的快速回答。添加庫幫助,現在我得到一個空指針異常,但它似乎在其他stackoverflow線程回答,如:http://stackoverflow.com/questions/6038776/android-monkeyrunner-on-jython-has-got-空指針異常 – jjung