Java Android Robotium测试,运行时异常无法从主应用程序线程调用此方法

Java Android Robotium测试,运行时异常无法从主应用程序线程调用此方法,java,android,robotium,Java,Android,Robotium,因此,我正在使用Robotium测试我的android应用程序,当我点击我列表中的项目时,它将通过solo.clickInList(0,1)使用给我 java.lang.RuntimeException: This method can not be called from the main application thread at android.app.Instrumentation.validateNotAppThread(Instrumentation.java:1787) at an

因此,我正在使用Robotium测试我的android应用程序,当我点击我列表中的项目时,它将通过
solo.clickInList(0,1)使用给我

java.lang.RuntimeException: This method can not be called from the main application thread
at android.app.Instrumentation.validateNotAppThread(Instrumentation.java:1787)
at android.app.Instrumentation.runOnMainSync(Instrumentation.java:348)
at com.robotium.solo.Scroller.scrollListToLine(Scroller.java:326)
at com.robotium.solo.Scroller.scrollList(Scroller.java:276)
at com.robotium.solo.Scroller.scroll(Scroller.java:195)
at com.robotium.solo.Scroller.scroll(Scroller.java:156)
at com.robotium.solo.Scroller.scrollDown(Scroller.java:169)
at com.robotium.solo.Waiter.waitForView(Waiter.java:154)
at com.robotium.solo.Waiter.waitForAndGetView(Waiter.java:521)
at com.robotium.solo.Clicker.clickInList(Clicker.java:516)
at com.robotium.solo.Solo.clickInList(Solo.java:1244)
at com.teamname.tutortrader.AvailableSessionsActivityTest.testViewOneSession(AvailableSessionsActivityTest.java:119)
at android.test.InstrumentationTestCase.runMethod(InstrumentationTestCase.java:214)
at android.test.InstrumentationTestCase.access$000(InstrumentationTestCase.java:36)
at android.test.InstrumentationTestCase$2.run(InstrumentationTestCase.java:189)
at android.app.Instrumentation$SyncRunnable.run(Instrumentation.java:1855)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)

我正在函数顶部使用
@UiThreadTest

正如我在这里发现的,它看起来像机器人中的一只虫子。 . 不用机器人,你也可以自己做同样的事情

public void onListViewItemClick(){
Activity=getActivity();
final ListView ListView=(ListView)activity.findviewbyd(android.R.id.list);
getInstrumentation().runOnMainSync(新的Runnable()命令){
@凌驾
公开募捐{
performItemClick(listView.getAdapter().getView(0,null,null),0,listView.getItemIdAtPosition(0));
}
});

}

我正在使用robotium 5.2.1,这仍然是一个问题吗?但问题应该得到解决。可能是注释@UiThreadTest造成了混乱。正如文档中所写,请注意,当存在此注释时,可能不会使用检测方法。你试过移除它吗?如果您有其他应该在主线程上运行的方法,则可以使用runOnMainSync。当我删除
@UiThreadTest
时,它会给我
java.lang.IllegalStateException
。我来看看RunnonMainSync是怎么工作的好吧这是我的错与机器人无关。您是对的,这是@uithread测试。我在做一些随机的适配器的东西,把它搞乱了。谢谢你的帮助