跑猴问题。 java.lang.ClassCastException:使用 SameAs() 方法时
我从源代码构建 SDK。 我想使用以下脚本:
img=MonkeyRunner.loadImageFromFile(path='/home/alsu/monkeyrunner/device.png')
img_1=device.takeSnapshot()
img_1.sameAs(img, 1)
但出现此错误:
File "/home/semc/monkey/out/host/linux-x86/sdk/android-sdk_eng.semc_linux-x86/tools/test.py", line 23, in <module>
if img_1.sameAs(img,1):
at com.android.monkeyrunner.MonkeyImage.sameAs(MonkeyImage.java:138)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
java.lang.ClassCastException: java.lang.ClassCastException: org.python.core.PySingleton cannot be cast to com.android.monkeyrunner.core.IMonkeyImage
请帮忙。
I build SDK from source code.
And I want to use the following script:
img=MonkeyRunner.loadImageFromFile(path='/home/alsu/monkeyrunner/device.png')
img_1=device.takeSnapshot()
img_1.sameAs(img, 1)
But this error occurs:
File "/home/semc/monkey/out/host/linux-x86/sdk/android-sdk_eng.semc_linux-x86/tools/test.py", line 23, in <module>
if img_1.sameAs(img,1):
at com.android.monkeyrunner.MonkeyImage.sameAs(MonkeyImage.java:138)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
java.lang.ClassCastException: java.lang.ClassCastException: org.python.core.PySingleton cannot be cast to com.android.monkeyrunner.core.IMonkeyImage
Please help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
MonkeyImage.sameAs() 被破坏了——无论你传递给它什么,你都会得到这个错误。
解决方法:使用convertToBytes():
更新:2011年10月27日:比较快照的一部分
根据kaciula的评论,这是从快照中删除状态栏的代码:
MonkeyImage.sameAs() is just broken -- it doesn't matter what you pass to it, you'll get that error.
Workaround: use convertToBytes():
Update: Oct 27, 2011: comparing portion of snapshot
As per kaciula's comment, this is the code to remove the status bar from the snapshot:
SDKTools Revision 12 也有同样的问题。
更新到 SDKTools Revision 15 解决了我的问题。
Had the same problem with SDKTools Revision 12.
Update to SDKTools Revision 15 solved the issue for me.
抱歉这个问题。此更改应该可以解决问题:
https://review.source.android.com/# /c/25618/
Sorry for the issue. This change should fix the problem:
https://review.source.android.com/#/c/25618/
我在其他地方也遇到了类似的问题。尝试使用 img_1.sameAs(img, 1.0) 代替 img_1.sameAs(img, 1)。 SameAs() 函数采用浮点值。这应该不重要,因为它是 python...但它是 Jython - python 和 java 中最糟糕的一切都集中在一个地方;-)
I had similar problem elsewhere. Instead of img_1.sameAs(img, 1) try img_1.sameAs(img, 1.0). The sameAs() function takes float value. It shouldn't matter since it is python... but it is Jython - everything the worst of python and java in one place ;-)
sameAs
工作得很好,直到您将图像文件移动到其他文件夹并再次加载为止。奇怪的错误...稍后编辑:
我想我已经弄清楚了。问题似乎是当文件名无效时
MonkeyRunner.loadImageFromFile()
不会给出错误。例如,像
MonkeyRunner.loadImageFromFile("d:\p.png")
这样的东西就可以正常工作,但是像MonkeyRunner.loadImageFromFile("d:\t.png")< /code> 将不起作用。原因很简单:
\t
是一个特殊的序列。解决方案是使用
\\\
或/
作为文件夹分隔符。sameAs
works just fine until you move the image file to a different folder and load it again. Strange bug...Later edit:
I think I got to the bottom of this. The problem seems to be that
MonkeyRunner.loadImageFromFile()
is not giving an error when the file name is not a valid one.For example, something like
MonkeyRunner.loadImageFromFile("d:\p.png")
will work just fine, but something likeMonkeyRunner.loadImageFromFile("d:\t.png")
will not work. The reason is quite simple:\t
is a special sequence.The solution is to use
\\\
or/
as folder separators.当我使用
sameAs()
时,我也遇到了类似的问题。我的问题是由三个原因引起的:两个图像的分辨率不同,因此
sameAs
函数在运行时中断。图片路径错误。即使我使用了错误的路径,
loadImageFromFile()
也从未向我们提及过。所以我们应该判断这个路径是否正确。SDK 版本较差。就我而言,我使用了 SDK_r23。
I was also confronted with a similar problem when I used
sameAs()
. My problem is caused by three reasons:Two images are of different resolutions, so the
sameAs
function breaks at runtime.The images path is wrong. Even though I used the wrong path,
loadImageFromFile()
never mentions it to us. So we should determine whether this path is correct or not.Poor SDK version. In my case, I used SDK_r23.