13

当我运行我的 android UIAutomator 代码时,它显示以下错误。

INSTRUMENTATION_RESULT:shortMsg=java.lang.RuntimeException
INSTRUMENTATION_RESULT:longMsg=com.android.ui.testing
INSTRUMENTATION_CODE:0

我刚刚运行了 developer.android.com 中给出的示例代码
如何解决这个错误?

日志附在下面:

01-05 01:07:53.559: D/AndroidRuntime(5712): >>>>>> AndroidRuntime START com.android.internal.os.RuntimeInit <<<<<<
01-05 01:07:53.559: D/AndroidRuntime(5712): CheckJNI is ON
01-05 01:07:53.559: E/AndroidRuntime(5712): cannot open customer xml file
01-05 01:07:53.559: E/AndroidRuntime(5712): /system/csc/customer.xml can't open file
01-05 01:07:53.564: D/AndroidRuntime(5712): readGMSProperty: start
01-05 01:07:53.564: D/AndroidRuntime(5712): readGMSProperty: already setted!!
01-05 01:07:53.564: D/AndroidRuntime(5712): readGMSProperty: end
01-05 01:07:53.589: D/dalvikvm(5712): Trying to load lib libjavacore.so 0x0
01-05 01:07:53.599: D/dalvikvm(5712): Added shared lib libjavacore.so 0x0
01-05 01:07:53.609: D/dalvikvm(5712): Trying to load lib libnativehelper.so 0x0
01-05 01:07:53.609: D/dalvikvm(5712): Added shared lib libnativehelper.so 0x0
01-05 01:07:53.664: I/dalvikvm(5712): Zip is good, but no classes.dex inside, and no valid .odex file in the same directory
01-05 01:07:53.874: D/dalvikvm(5712): Note: class Landroid/app/ActivityManagerNative; has 152 unimplemented (abstract) methods
01-05 01:07:53.924: D/AndroidRuntime(5712): Calling main entry com.android.commands.uiautomator.Launcher
01-05 01:07:53.934: D/AndroidRuntime(5712): Shutting down VM
01-05 01:07:53.934: W/dalvikvm(5712): threadid=1: thread exiting with uncaught exception (group=0x40ffa2a0)
01-05 01:07:53.939: E/UiAutomatorTestRunner(5712): uncaught exception
01-05 01:07:53.939: E/UiAutomatorTestRunner(5712): java.lang.RuntimeException: com.uia.example.my.LaunchSettings
01-05 01:07:53.939: E/UiAutomatorTestRunner(5712):  at com.android.uiautomator.testrunner.UiAutomatorTestRunner.start(UiAutomatorTestRunner.java:95)
01-05 01:07:53.939: E/UiAutomatorTestRunner(5712):  at com.android.uiautomator.testrunner.UiAutomatorTestRunner.run(UiAutomatorTestRunner.java:82)
01-05 01:07:53.939: E/UiAutomatorTestRunner(5712):  at com.android.commands.uiautomator.RunTestCommand.run(RunTestCommand.java:76)
01-05 01:07:53.939: E/UiAutomatorTestRunner(5712):  at com.android.commands.uiautomator.Launcher.main(Launcher.java:83)
01-05 01:07:53.939: E/UiAutomatorTestRunner(5712):  at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method)
01-05 01:07:53.939: E/UiAutomatorTestRunner(5712):  at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:237)
01-05 01:07:53.939: E/UiAutomatorTestRunner(5712):  at dalvik.system.NativeStart.main(Native Method)
01-05 01:07:53.939: E/UiAutomatorTestRunner(5712): Caused by: java.lang.ClassNotFoundException: com.uia.example.my.LaunchSettings
01-05 01:07:53.939: E/UiAutomatorTestRunner(5712):  at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
01-05 01:07:53.939: E/UiAutomatorTestRunner(5712):  at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
01-05 01:07:53.939: E/UiAutomatorTestRunner(5712):  at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
01-05 01:07:53.939: E/UiAutomatorTestRunner(5712):  at com.android.uiautomator.testrunner.TestCaseCollector.addTestClass(TestCaseCollector.java:83)
01-05 01:07:53.939: E/UiAutomatorTestRunner(5712):  at com.android.uiautomator.testrunner.TestCaseCollector.addTestClass(TestCaseCollector.java:71)
01-05 01:07:53.939: E/UiAutomatorTestRunner(5712):  at com.android.uiautomator.testrunner.TestCaseCollector.addTestClasses(TestCaseCollector.java:52)
01-05 01:07:53.939: E/UiAutomatorTestRunner(5712):  at com.android.uiautomator.testrunner.UiAutomatorTestRunner.start(UiAutomatorTestRunner.java:92)
01-05 01:07:53.939: E/UiAutomatorTestRunner(5712):  ... 6 more
01-05 01:07:53.944: I/AndroidRuntime(5712): VM exiting with result code -1.
4

4 回答 4

3

如果在运行 uiautomator 测试时遇到 ClassNotFindException :

我们中的一些人收到此错误是因为他们的 ROM 将文件夹 /data/dalvik-cache 置于只读模式。使用 Cyanogen 的 S3 发生在我身上。

在这种情况下,输入 bash :

adb shell 
su
chmod 777 /data/dalvik-cache
exit

重新运行您的测试,这应该可以工作。由于 dalvik-cache 对应用程序已锁定,因此 uiautomator 无法要求 dalvik 解压缩测试的 jar,并且 dalvik 不会找到它的类。

于 2012-12-10T17:21:29.363 回答
1

查看是否删除 @UiThreadTest 注释或删除 runOnUiThread() 调用或重构您的测试工作。但是没有 logcat,很难理解它的来源。

于 2012-12-07T23:20:44.243 回答
0

有同样的问题。我见过的大多数演示都表明将 jar 安装到 /data/local/tmp/。我看到其他人表示尝试将其安装到您的 SD 卡 (/storage/sdcard0)。这样做之后,它起作用了。似乎是读取权限的问题。

于 2014-03-08T15:14:15.670 回答
-1

我通过使用“ant build”来创建我的 jar 解决了这个错误。如果你在 eclipse 中使用 export 创建一个 jar 文件,生成的类文件中可能有一些错误,因此上述类未找到错误。

于 2012-12-10T10:50:53.503 回答