Android Junit测试失败,返回“0”;只有创建视图层次结构的原始线程才能接触其视图。”;

Android Junit测试失败,返回“0”;只有创建视图层次结构的原始线程才能接触其视图。”;,android,robotium,Android,Robotium,我对安卓非常陌生,正在使用Robotium编写一些基本的安卓测试,但也有例外 "android.view.ViewRoot$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views." 下面是基本的测试用例描述:- 测试用例:- public void testSearch() { Activ

我对安卓非常陌生,正在使用Robotium编写一些基本的安卓测试,但也有例外

"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");
    }
任何建议,我可以修改我的代码将不胜感激

@UiThreadTest
public void yourMethod() {
@UiThreadTest注释告诉Android构建此方法,以便它在UI线程上运行。这允许该方法更改被测应用程序中微调器小部件的状态。@UiThreadTest的使用表明,如果需要,可以在UI线程上运行整个方法


我猜您正在尝试从非UI线程更新UI。因此,您需要将代码放入
runOnUiThread()


我猜这是因为您的测试用例试图关闭锁屏
ActivityName.this.runOnUiThread(new Runnable() {

            public void run() {
                // your code to update the UI
            }
        });