Codinglangzi 发表于 2019-7-2 11:32:17

Monkeyrunner截图报错

刚学习了一天,简单copy了个截图的代码,貌似只成功了一次,之后全部都报一样的错误。
from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice, MonkeyImage
device = MonkeyRunner.waitForConnection()
#device.press('KEYCODE_HOME',MonkeyDevice.DOWN_AND_UP)
pict = device.takeSnapshot()
MonkeyRunner.sleep(2)
pict.writeToFile(r'C:\WuZhongjian\Doc\pic2.png','png')

下面是命令行窗口报得错误:
C:\Windows\System32>monkeyrunner C:\WuZhongjian\Doc\Android\Test4.py
190702 11:17:02.921:S Unable t
o take snapshot
190702 11:17:02.921:S java.io.I
OException: EOF
190702 11:17:02.921:S at com.a
ndroid.ddmlib.AdbHelper.read(AdbHelper.java:874)
190702 11:17:02.921:S at com.a
ndroid.ddmlib.AdbHelper.getFrameBuffer(AdbHelper.java:333)
190702 11:17:02.921:S at com.a
ndroid.ddmlib.Device.getScreenshot(Device.java:545)
190702 11:17:02.921:S at com.a
ndroid.ddmlib.Device.getScreenshot(Device.java:539)
190702 11:17:02.921:S at com.a
ndroid.chimpchat.adb.AdbChimpDevice.takeSnapshot(AdbChimpDevice.java:210)
190702 11:17:02.921:S at com.a
ndroid.monkeyrunner.MonkeyDevice.takeSnapshot(MonkeyDevice.java:92)
190702 11:17:02.921:S at sun.r
eflect.NativeMethodAccessorImpl.invoke0(Native Method)
190702 11:17:02.921:S at sun.r
eflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
190702 11:17:02.921:S at sun.r
eflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

190702 11:17:02.921:S at java.
lang.reflect.Method.invoke(Method.java:498)
190702 11:17:02.921:S at org.p
ython.core.PyReflectedFunction.__call__(PyReflectedFunction.java:186)
190702 11:17:02.921:S at org.p
ython.core.PyReflectedFunction.__call__(PyReflectedFunction.java:204)
190702 11:17:02.921:S at org.p
ython.core.PyObject.__call__(PyObject.java:387)
190702 11:17:02.921:S at org.p
ython.core.PyObject.__call__(PyObject.java:391)
190702 11:17:02.921:S at org.p
ython.core.PyMethod.__call__(PyMethod.java:109)
190702 11:17:02.921:S at org.p
ython.pycode._pyx0.f$0(C:\WuZhongjian\Doc\Android\Test4.py:10)
190702 11:17:02.921:S at org.p
ython.pycode._pyx0.call_function(C:\WuZhongjian\Doc\Android\Test4.py)
190702 11:17:02.921:S at org.p
ython.core.PyTableCode.call(PyTableCode.java:165)
190702 11:17:02.921:S at org.p
ython.core.PyCode.call(PyCode.java:18)
190702 11:17:02.921:S at org.p
ython.core.Py.runCode(Py.java:1275)
190702 11:17:02.921:S at org.p
ython.core.__builtin__.execfile_flags(__builtin__.java:522)
190702 11:17:02.921:S at org.p
ython.util.PythonInterpreter.execfile(PythonInterpreter.java:225)
190702 11:17:02.921:S at com.a
ndroid.monkeyrunner.ScriptRunner.run(ScriptRunner.java:116)
190702 11:17:02.921:S at com.a
ndroid.monkeyrunner.MonkeyRunnerStarter.run(MonkeyRunnerStarter.java:77)
190702 11:17:02.921:S at com.a
ndroid.monkeyrunner.MonkeyRunnerStarter.main(MonkeyRunnerStarter.java:189)
190702 11:17:02.946:S Scri
pt terminated due to an exception
190702 11:17:02.946:S Trace
back (most recent call last):
File "C:\WuZhongjian\Doc\Android\Test4.py", line 9, in <module>
    photos=photos.getSubImage((42,32,1000,224))
      at com.android.monkeyrunner.MonkeyImage.getSubImage(MonkeyImage.java:159
)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:62)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:498)

java.lang.NullPointerException: java.lang.NullPointerException

190702 11:17:02.946:S
at org.python.core.Py.JavaError(Py.java:495)
190702 11:17:02.946:S
at org.python.core.Py.JavaError(Py.java:488)
190702 11:17:02.946:S
at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java:188)
190702 11:17:02.946:S
at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java:204)
190702 11:17:02.946:S
at org.python.core.PyObject.__call__(PyObject.java:404)
190702 11:17:02.946:S
at org.python.core.PyObject.__call__(PyObject.java:408)
190702 11:17:02.946:S
at org.python.core.PyMethod.__call__(PyMethod.java:124)
190702 11:17:02.946:S
at org.python.pycode._pyx0.f$0(C:\WuZhongjian\Doc\Android\Test4.py:10)
190702 11:17:02.946:S
at org.python.pycode._pyx0.call_function(C:\WuZhongjian\Doc\Android\Test4.py)
190702 11:17:02.946:S
at org.python.core.PyTableCode.call(PyTableCode.java:165)
190702 11:17:02.946:S
at org.python.core.PyCode.call(PyCode.java:18)
190702 11:17:02.946:S
at org.python.core.Py.runCode(Py.java:1275)
190702 11:17:02.946:S
at org.python.core.__builtin__.execfile_flags(__builtin__.java:522)
190702 11:17:02.946:S
at org.python.util.PythonInterpreter.execfile(PythonInterpreter.java:225)
190702 11:17:02.946:S
at com.android.monkeyrunner.ScriptRunner.run(ScriptRunner.java:116)
190702 11:17:02.946:S
at com.android.monkeyrunner.MonkeyRunnerStarter.run(MonkeyRunnerStarter.java:77)

190702 11:17:02.946:S
at com.android.monkeyrunner.MonkeyRunnerStarter.main(MonkeyRunnerStarter.java:18
9)
190702 11:17:02.946:S Cause
d by: java.lang.NullPointerException
190702 11:17:02.946:S
at com.android.monkeyrunner.MonkeyImage.getSubImage(MonkeyImage.java:159)
190702 11:17:02.946:S
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
190702 11:17:02.946:S
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

190702 11:17:02.946:S
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.
java:43)
190702 11:17:02.946:S
at java.lang.reflect.Method.invoke(Method.java:498)
190702 11:17:02.946:S
at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java:186)
190702 11:17:02.946:S
... 14 more

Codinglangzi 发表于 2019-7-2 11:33:02

有大神嘛帮助解答下困扰了一天了

海海豚 发表于 2019-7-2 13:49:09

把截图写入的路径更换一下试试呢,C盘权限挺多

Codinglangzi 发表于 2019-7-2 15:23:39

海海豚 发表于 2019-7-2 13:49
把截图写入的路径更换一下试试呢,C盘权限挺多

这个也考虑过了,插个U盘进去也不行。把路径那行注释了,我发现也报错,就是说device.takeSnapshot()这个东东就会报错。。。

Codinglangzi 发表于 2019-7-3 14:28:57

自己更新下最新进展,用了个老的安卓6.0的手机,完全没有问题
页: [1]
查看完整版本: Monkeyrunner截图报错