我对Android非常陌生,正在使用Robotium编写一些基础的Android测试,但是测试失败并出现以下异常:
"android.view.ViewRoot$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views."
以下是基本测试用例的描述:
测试用例:
public void testSearch() {
Activity a = getActivity();
SearchItemActivity search = new SearchItemActivity(solo);
search.searchText("ipod", a);
}
SearchItemActivity.searchText(String) is defined as
public void searchText(final String search, Activity act) {
Button v = (Button) act
.findViewById(com.test.mobile.R.id.text_search_field);
((Button) v).setText("");
((Button) v).setText(search);
solo.sendKey(Solo.ENTER);
solo.waitForActivity("FoundItemdDetailActivity");
solo.assertCurrentActivity("Expected FoundItemDetail activity","FoundItemdDetailActivity");
}
有什么建议可以修改我的代码将不胜感激