【问题标题】:Android MonkeyRunner exceptionAndroid MonkeyRunner 异常
【发布时间】:2012-10-26 09:44:57
【问题描述】:

我正在尝试从 Eclipse (4.2) 运行 MonkeyRunner Android 测试工具。 我安装了 Eclipse PyDev 插件以及 Jython 2.5.1。 我的 PyDev 解释器设置为 Jython / 2.5。

我在 Eclipse 中用一个简单的 jython 文件创建了一个 Jython 项目:

# Imports the monkeyrunner modules used by this program
from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice

# Connects to the current device, returning a MonkeyDevice object
device = MonkeyRunner.waitForConnection()

现在,当我从 Eclipse(项目 > 以 JythonProject 运行)启动它时,我收到以下异常:

Traceback (most recent call last):
  File "C:\svnrepository\trunk\JythonProject\src\main.py", line 10, in <module>
    device = MonkeyRunner.waitForConnection()
    at com.android.monkeyrunner.MonkeyRunner.waitForConnection(MonkeyRunner.java:75)
    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)
 java.lang.NullPointerException: java.lang.NullPointerException

知道有什么问题吗?

【问题讨论】:

    标签: android testing jython monkeyrunner


    【解决方案1】:

    Diego Torres Milano 有一篇关于如何配置 PyDev 以将其与 monkeyrunner 一起使用的帖子。我按照his 的步骤进行操作,就我而言,一切正常。

    简而言之,首先您需要更改您的 Android 安装。你需要将你的monkeyrunner 工具重命名为monkeyrunner-original。然后你需要在同一个文件夹中编写shell脚本(命名为monkeyrunner),它将以特定方式调用monkeyrunner-original。

    Linux 脚本:

    # /bin/bash
    if [ "$1" = '-u' ]
    then
     shift
    fi
    
    exec /opt/android-sdk-linux_86/tools/monkeyrunner-original "$@" 
    

    Windows 脚本:

    REM
    @echo off if("%1")==("-u") shift "C:\Program Files\Android\android-sdk\tools"/monkeyrunner-original %1 %2 %3 %4 %5 %6 %7 %8
    

    然后在 Eclipse 中,您应该定义新的 Python 解释器(不是 Jython)并将其指向创建的脚本。

    【讨论】:

      猜你喜欢
      • 2012-05-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-19
      • 2015-02-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多