Monkeyrunner 的 takeSnapshot() 错误

发布于 2024-12-11 03:59:57 字数 11362 浏览 0 评论 0原文

我正在测试 Monkeyrunner 并使用下面的 .py 文件进行屏幕截图。

生成屏幕捕获图像,但有时会在“resulet = device.takeSnapshot()”中出现错误,

我不知道问题是什么。 我用Eclipse测试过。 (Eclipse -> AVD , Skin WVGA854)

请帮助我~谢谢~

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

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

    # Installs the Android package. Notice that this method returns a boolean, so you can test
    # to see if the installation worked.
    #device.installPackage('D:\\study_java\\monkeyrunner\\HelloAndroid.apk')

    # sets a variable with the package's internal name
    package = 'com.example.helloandroid'

    # sets a variable with the name of an Activity in the package
    activity = 'com.example.helloandroid.HelloAndroid'

    # sets the name of the component to start
    runComponent = package + '/' + activity

    # Runs the component
    device.startActivity(component=runComponent)

    # Takes a screenshot
    MonkeyRunner.sleep(0.5)
    result = device.takeSnapshot()
    # Writes the screenshot to a file
    result.writeToFile('D:\\study_java\\monkeyrunner\\screen_shot.png','png')

下面是错误日志。

    D:\study_java\monkeyrunner>monkeyrunner d:\study_java\monkeyrunner\monkeytest.py

    111019 16:47:17.000:S [main] [com.android.monkeyrunner.adb.AdbMonkeyDevice] Unab
    le to take snapshot
    111019 16:47:17.000:S [main] [com.android.monkeyrunner.adb.AdbMonkeyDevice]java.
    io.IOException: EOF
    111019 16:47:17.000:S [main] [com.android.monkeyrunner.adb.AdbMonkeyDevice]
    at com.android.ddmlib.AdbHelper.read(AdbHelper.java:643)
    111019 16:47:17.000:S [main] [com.android.monkeyrunner.adb.AdbMonkeyDevice]
    at com.android.ddmlib.AdbHelper.read(AdbHelper.java:616)
    111019 16:47:17.000:S [main] [com.android.monkeyrunner.adb.AdbMonkeyDevice]
    at com.android.ddmlib.AdbHelper.getFrameBuffer(AdbHelper.java:326)
    111019 16:47:17.000:S [main] [com.android.monkeyrunner.adb.AdbMonkeyDevice]
    at com.android.ddmlib.Device.getScreenshot(Device.java:270)
    111019 16:47:17.000:S [main] [com.android.monkeyrunner.adb.AdbMonkeyDevice]
    at com.android.monkeyrunner.adb.AdbMonkeyDevice.takeSnapshot(AdbMonkeyDevice.jav
    a:197)
    111019 16:47:17.000:S [main] [com.android.monkeyrunner.adb.AdbMonkeyDevice]
    at com.android.monkeyrunner.MonkeyDevice.takeSnapshot(MonkeyDevice.java:83)
    111019 16:47:17.000:S [main] [com.android.monkeyrunner.adb.AdbMonkeyDevice]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    111019 16:47:17.000:S [main] [com.android.monkeyrunner.adb.AdbMonkeyDevice]
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    111019 16:47:17.000:S [main] [com.android.monkeyrunner.adb.AdbMonkeyDevice]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    111019 16:47:17.000:S [main] [com.android.monkeyrunner.adb.AdbMonkeyDevice]
    at java.lang.reflect.Method.invoke(Unknown Source)
    111019 16:47:17.000:S [main] [com.android.monkeyrunner.adb.AdbMonkeyDevice]
    at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java:175)
    111019 16:47:17.000:S [main] [com.android.monkeyrunner.adb.AdbMonkeyDevice]
    at org.python.core.PyObject.__call__(PyObject.java:355)
    111019 16:47:17.000:S [main] [com.android.monkeyrunner.adb.AdbMonkeyDevice]
    at org.python.core.PyMethod.__call__(PyMethod.java:215)
    111019 16:47:17.000:S [main] [com.android.monkeyrunner.adb.AdbMonkeyDevice]
    at org.python.core.PyMethod.instancemethod___call__(PyMethod.java:221)
    111019 16:47:17.000:S [main] [com.android.monkeyrunner.adb.AdbMonkeyDevice]
    at org.python.core.PyMethod.__call__(PyMethod.java:206)
    111019 16:47:17.000:S [main] [com.android.monkeyrunner.adb.AdbMonkeyDevice]
    at org.python.core.PyObject.__call__(PyObject.java:381)
    111019 16:47:17.000:S [main] [com.android.monkeyrunner.adb.AdbMonkeyDevice]
    at org.python.core.PyObject.__call__(PyObject.java:385)
    111019 16:47:17.000:S [main] [com.android.monkeyrunner.adb.AdbMonkeyDevice]
    at org.python.pycode._pyx0.f$0(d:\study_java\monkeyrunner\monkeytest.py:37)
    111019 16:47:17.000:S [main] [com.android.monkeyrunner.adb.AdbMonkeyDevice]
    at org.python.pycode._pyx0.call_function(d:\study_java\monkeyrunner\monkeytest.p
    y)
    111019 16:47:17.000:S [main] [com.android.monkeyrunner.adb.AdbMonkeyDevice]
    at org.python.core.PyTableCode.call(PyTableCode.java:165)
    111019 16:47:17.000:S [main] [com.android.monkeyrunner.adb.AdbMonkeyDevice]
    at org.python.core.PyCode.call(PyCode.java:18)
    111019 16:47:17.000:S [main] [com.android.monkeyrunner.adb.AdbMonkeyDevice]
    at org.python.core.Py.runCode(Py.java:1197)
    111019 16:47:17.000:S [main] [com.android.monkeyrunner.adb.AdbMonkeyDevice]
    at org.python.core.__builtin__.execfile_flags(__builtin__.java:538)
    111019 16:47:17.000:S [main] [com.android.monkeyrunner.adb.AdbMonkeyDevice]
    at org.python.util.PythonInterpreter.execfile(PythonInterpreter.java:156)
    111019 16:47:17.000:S [main] [com.android.monkeyrunner.adb.AdbMonkeyDevice]
    at com.android.monkeyrunner.ScriptRunner.run(ScriptRunner.java:116)
    111019 16:47:17.000:S [main] [com.android.monkeyrunner.adb.AdbMonkeyDevice]
    at com.android.monkeyrunner.MonkeyRunnerStarter.run(MonkeyRunnerStarter.java:93)

    111019 16:47:17.000:S [main] [com.android.monkeyrunner.adb.AdbMonkeyDevice]
    at com.android.monkeyrunner.MonkeyRunnerStarter.main(MonkeyRunnerStarter.java:20
    3)
    111019 16:47:17.000:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions] Scri
    pt terminated due to an exception
    111019 16:47:17.000:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]Trace
    back (most recent call last):
      File "d:\study_java\monkeyrunner\monkeytest.py", line 27, in <module>
        result.writeToFile('D:\\study_java\\monkeyrunner\\screen_shot.png','png')
            at com.android.monkeyrunner.MonkeyImage.writeToFile(MonkeyImage.java:85)

            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

    111019 16:47:17.000:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
    at org.python.core.PyException.fillInStackTrace(PyException.java:70)
    111019 16:47:17.000:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
    at java.lang.Throwable.<init>(Throwable.java:181)
    111019 16:47:17.000:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
    at java.lang.Exception.<init>(Unknown Source)
    111019 16:47:17.000:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
    at java.lang.RuntimeException.<init>(Unknown Source)
    111019 16:47:17.000:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
    at org.python.core.PyException.<init>(PyException.java:46)
    111019 16:47:17.000:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
    at org.python.core.PyException.<init>(PyException.java:43)
    111019 16:47:17.000:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
    at org.python.core.Py.JavaError(Py.java:455)
    111019 16:47:17.000:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
    at org.python.core.Py.JavaError(Py.java:448)
    111019 16:47:17.000:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
    at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java:177)
    111019 16:47:17.000:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
    at org.python.core.PyObject.__call__(PyObject.java:355)
    111019 16:47:17.000:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
    at org.python.core.PyMethod.__call__(PyMethod.java:215)
    111019 16:47:17.000:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
    at org.python.core.PyMethod.instancemethod___call__(PyMethod.java:221)
    111019 16:47:17.000:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
    at org.python.core.PyMethod.__call__(PyMethod.java:206)
    111019 16:47:17.000:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
    at org.python.core.PyObject.__call__(PyObject.java:414)
    111019 16:47:17.000:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
    at org.python.core.PyObject.__call__(PyObject.java:418)
    111019 16:47:17.000:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
    at org.python.pycode._pyx0.f$0(d:\study_java\monkeyrunner\monkeytest.py:37)
    111019 16:47:17.000:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
    at org.python.pycode._pyx0.call_function(d:\study_java\monkeyrunner\monkeytest.p
    y)
    111019 16:47:17.000:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
    at org.python.core.PyTableCode.call(PyTableCode.java:165)
    111019 16:47:17.000:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
    at org.python.core.PyCode.call(PyCode.java:18)
    111019 16:47:17.000:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
    at org.python.core.Py.runCode(Py.java:1197)
    111019 16:47:17.000:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
    at org.python.core.__builtin__.execfile_flags(__builtin__.java:538)
    111019 16:47:17.000:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
    at org.python.util.PythonInterpreter.execfile(PythonInterpreter.java:156)
    111019 16:47:17.000:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
    at com.android.monkeyrunner.ScriptRunner.run(ScriptRunner.java:116)
    111019 16:47:17.000:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
    at com.android.monkeyrunner.MonkeyRunnerStarter.run(MonkeyRunnerStarter.java:93)

    111019 16:47:17.000:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
    at com.android.monkeyrunner.MonkeyRunnerStarter.main(MonkeyRunnerStarter.java:20
    3)
    111019 16:47:17.000:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]Cause
    d by: java.lang.NullPointerException
    111019 16:47:17.000:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
    at com.android.monkeyrunner.MonkeyImage.writeToFile(MonkeyImage.java:85)
    111019 16:47:17.000:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    111019 16:47:17.000:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    111019 16:47:17.000:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    111019 16:47:17.000:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
    at java.lang.reflect.Method.invoke(Unknown Source)
    111019 16:47:17.000:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
    at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java:175)
    111019 16:47:17.000:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
    ... 16 more

    D:\study_java\monkeyrunner>

I am testing monkeyrunner and using below .py file for screencapture.

screencapture image is generated but sometimes it occurs error in "resulet = device.takeSnapshot()"

I don't know what's the problem.
I have tested it with Eclipse. (Eclipse -> AVD , Skin WVGA854)

Please help me~ Thanks~

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

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

    # Installs the Android package. Notice that this method returns a boolean, so you can test
    # to see if the installation worked.
    #device.installPackage('D:\\study_java\\monkeyrunner\\HelloAndroid.apk')

    # sets a variable with the package's internal name
    package = 'com.example.helloandroid'

    # sets a variable with the name of an Activity in the package
    activity = 'com.example.helloandroid.HelloAndroid'

    # sets the name of the component to start
    runComponent = package + '/' + activity

    # Runs the component
    device.startActivity(component=runComponent)

    # Takes a screenshot
    MonkeyRunner.sleep(0.5)
    result = device.takeSnapshot()
    # Writes the screenshot to a file
    result.writeToFile('D:\\study_java\\monkeyrunner\\screen_shot.png','png')

Below is error log.

    D:\study_java\monkeyrunner>monkeyrunner d:\study_java\monkeyrunner\monkeytest.py

    111019 16:47:17.000:S [main] [com.android.monkeyrunner.adb.AdbMonkeyDevice] Unab
    le to take snapshot
    111019 16:47:17.000:S [main] [com.android.monkeyrunner.adb.AdbMonkeyDevice]java.
    io.IOException: EOF
    111019 16:47:17.000:S [main] [com.android.monkeyrunner.adb.AdbMonkeyDevice]
    at com.android.ddmlib.AdbHelper.read(AdbHelper.java:643)
    111019 16:47:17.000:S [main] [com.android.monkeyrunner.adb.AdbMonkeyDevice]
    at com.android.ddmlib.AdbHelper.read(AdbHelper.java:616)
    111019 16:47:17.000:S [main] [com.android.monkeyrunner.adb.AdbMonkeyDevice]
    at com.android.ddmlib.AdbHelper.getFrameBuffer(AdbHelper.java:326)
    111019 16:47:17.000:S [main] [com.android.monkeyrunner.adb.AdbMonkeyDevice]
    at com.android.ddmlib.Device.getScreenshot(Device.java:270)
    111019 16:47:17.000:S [main] [com.android.monkeyrunner.adb.AdbMonkeyDevice]
    at com.android.monkeyrunner.adb.AdbMonkeyDevice.takeSnapshot(AdbMonkeyDevice.jav
    a:197)
    111019 16:47:17.000:S [main] [com.android.monkeyrunner.adb.AdbMonkeyDevice]
    at com.android.monkeyrunner.MonkeyDevice.takeSnapshot(MonkeyDevice.java:83)
    111019 16:47:17.000:S [main] [com.android.monkeyrunner.adb.AdbMonkeyDevice]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    111019 16:47:17.000:S [main] [com.android.monkeyrunner.adb.AdbMonkeyDevice]
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    111019 16:47:17.000:S [main] [com.android.monkeyrunner.adb.AdbMonkeyDevice]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    111019 16:47:17.000:S [main] [com.android.monkeyrunner.adb.AdbMonkeyDevice]
    at java.lang.reflect.Method.invoke(Unknown Source)
    111019 16:47:17.000:S [main] [com.android.monkeyrunner.adb.AdbMonkeyDevice]
    at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java:175)
    111019 16:47:17.000:S [main] [com.android.monkeyrunner.adb.AdbMonkeyDevice]
    at org.python.core.PyObject.__call__(PyObject.java:355)
    111019 16:47:17.000:S [main] [com.android.monkeyrunner.adb.AdbMonkeyDevice]
    at org.python.core.PyMethod.__call__(PyMethod.java:215)
    111019 16:47:17.000:S [main] [com.android.monkeyrunner.adb.AdbMonkeyDevice]
    at org.python.core.PyMethod.instancemethod___call__(PyMethod.java:221)
    111019 16:47:17.000:S [main] [com.android.monkeyrunner.adb.AdbMonkeyDevice]
    at org.python.core.PyMethod.__call__(PyMethod.java:206)
    111019 16:47:17.000:S [main] [com.android.monkeyrunner.adb.AdbMonkeyDevice]
    at org.python.core.PyObject.__call__(PyObject.java:381)
    111019 16:47:17.000:S [main] [com.android.monkeyrunner.adb.AdbMonkeyDevice]
    at org.python.core.PyObject.__call__(PyObject.java:385)
    111019 16:47:17.000:S [main] [com.android.monkeyrunner.adb.AdbMonkeyDevice]
    at org.python.pycode._pyx0.f$0(d:\study_java\monkeyrunner\monkeytest.py:37)
    111019 16:47:17.000:S [main] [com.android.monkeyrunner.adb.AdbMonkeyDevice]
    at org.python.pycode._pyx0.call_function(d:\study_java\monkeyrunner\monkeytest.p
    y)
    111019 16:47:17.000:S [main] [com.android.monkeyrunner.adb.AdbMonkeyDevice]
    at org.python.core.PyTableCode.call(PyTableCode.java:165)
    111019 16:47:17.000:S [main] [com.android.monkeyrunner.adb.AdbMonkeyDevice]
    at org.python.core.PyCode.call(PyCode.java:18)
    111019 16:47:17.000:S [main] [com.android.monkeyrunner.adb.AdbMonkeyDevice]
    at org.python.core.Py.runCode(Py.java:1197)
    111019 16:47:17.000:S [main] [com.android.monkeyrunner.adb.AdbMonkeyDevice]
    at org.python.core.__builtin__.execfile_flags(__builtin__.java:538)
    111019 16:47:17.000:S [main] [com.android.monkeyrunner.adb.AdbMonkeyDevice]
    at org.python.util.PythonInterpreter.execfile(PythonInterpreter.java:156)
    111019 16:47:17.000:S [main] [com.android.monkeyrunner.adb.AdbMonkeyDevice]
    at com.android.monkeyrunner.ScriptRunner.run(ScriptRunner.java:116)
    111019 16:47:17.000:S [main] [com.android.monkeyrunner.adb.AdbMonkeyDevice]
    at com.android.monkeyrunner.MonkeyRunnerStarter.run(MonkeyRunnerStarter.java:93)

    111019 16:47:17.000:S [main] [com.android.monkeyrunner.adb.AdbMonkeyDevice]
    at com.android.monkeyrunner.MonkeyRunnerStarter.main(MonkeyRunnerStarter.java:20
    3)
    111019 16:47:17.000:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions] Scri
    pt terminated due to an exception
    111019 16:47:17.000:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]Trace
    back (most recent call last):
      File "d:\study_java\monkeyrunner\monkeytest.py", line 27, in <module>
        result.writeToFile('D:\\study_java\\monkeyrunner\\screen_shot.png','png')
            at com.android.monkeyrunner.MonkeyImage.writeToFile(MonkeyImage.java:85)

            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

    111019 16:47:17.000:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
    at org.python.core.PyException.fillInStackTrace(PyException.java:70)
    111019 16:47:17.000:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
    at java.lang.Throwable.<init>(Throwable.java:181)
    111019 16:47:17.000:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
    at java.lang.Exception.<init>(Unknown Source)
    111019 16:47:17.000:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
    at java.lang.RuntimeException.<init>(Unknown Source)
    111019 16:47:17.000:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
    at org.python.core.PyException.<init>(PyException.java:46)
    111019 16:47:17.000:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
    at org.python.core.PyException.<init>(PyException.java:43)
    111019 16:47:17.000:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
    at org.python.core.Py.JavaError(Py.java:455)
    111019 16:47:17.000:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
    at org.python.core.Py.JavaError(Py.java:448)
    111019 16:47:17.000:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
    at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java:177)
    111019 16:47:17.000:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
    at org.python.core.PyObject.__call__(PyObject.java:355)
    111019 16:47:17.000:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
    at org.python.core.PyMethod.__call__(PyMethod.java:215)
    111019 16:47:17.000:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
    at org.python.core.PyMethod.instancemethod___call__(PyMethod.java:221)
    111019 16:47:17.000:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
    at org.python.core.PyMethod.__call__(PyMethod.java:206)
    111019 16:47:17.000:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
    at org.python.core.PyObject.__call__(PyObject.java:414)
    111019 16:47:17.000:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
    at org.python.core.PyObject.__call__(PyObject.java:418)
    111019 16:47:17.000:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
    at org.python.pycode._pyx0.f$0(d:\study_java\monkeyrunner\monkeytest.py:37)
    111019 16:47:17.000:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
    at org.python.pycode._pyx0.call_function(d:\study_java\monkeyrunner\monkeytest.p
    y)
    111019 16:47:17.000:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
    at org.python.core.PyTableCode.call(PyTableCode.java:165)
    111019 16:47:17.000:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
    at org.python.core.PyCode.call(PyCode.java:18)
    111019 16:47:17.000:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
    at org.python.core.Py.runCode(Py.java:1197)
    111019 16:47:17.000:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
    at org.python.core.__builtin__.execfile_flags(__builtin__.java:538)
    111019 16:47:17.000:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
    at org.python.util.PythonInterpreter.execfile(PythonInterpreter.java:156)
    111019 16:47:17.000:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
    at com.android.monkeyrunner.ScriptRunner.run(ScriptRunner.java:116)
    111019 16:47:17.000:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
    at com.android.monkeyrunner.MonkeyRunnerStarter.run(MonkeyRunnerStarter.java:93)

    111019 16:47:17.000:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
    at com.android.monkeyrunner.MonkeyRunnerStarter.main(MonkeyRunnerStarter.java:20
    3)
    111019 16:47:17.000:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]Cause
    d by: java.lang.NullPointerException
    111019 16:47:17.000:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
    at com.android.monkeyrunner.MonkeyImage.writeToFile(MonkeyImage.java:85)
    111019 16:47:17.000:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    111019 16:47:17.000:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    111019 16:47:17.000:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    111019 16:47:17.000:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
    at java.lang.reflect.Method.invoke(Unknown Source)
    111019 16:47:17.000:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
    at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java:175)
    111019 16:47:17.000:S [main] [com.android.monkeyrunner.MonkeyRunnerOptions]
    ... 16 more

    D:\study_java\monkeyrunner>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

醉南桥 2024-12-18 03:59:57

你问这个问题已经很久了,但无论如何,这就是答案。当您尝试将屏幕截图保存在指定的文件夹中时,您的代码会出现异常。如果您将以下代码更改

result.writeToFile('D:\\study_java\\monkeyrunner\\screen_shot.png','png')

为:

result.writeToFile('D:/study_java/monkeyrunner/screen_shot.png','png')

那么您应该可以开始了!如果您遇到任何其他问题,请告诉我。

It has been so long since you asked this question but here is the answer anyway. Your code gives exception when you try to save the screen capture in the folder that you specified. If you change the following code:

result.writeToFile('D:\\study_java\\monkeyrunner\\screen_shot.png','png')

into:

result.writeToFile('D:/study_java/monkeyrunner/screen_shot.png','png')

Then you should be good to go! Please let me know if you encounter any other problems.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文