我刚开始使用Robotium。但是我似乎遇到了一个奇怪的问题。这是我的测试代码。

    public class TestMaindashboard extends ActivityInstrumentationTestCase2<AboutActivity>{

    private Solo solo;
    public TestMaindashboard() {
        super(AboutActivity.class);
    }

    public void setUp() throws Exception{
        super.setUp();
        solo = new Solo(getInstrumentation(), getActivity());
    }

    public void testSamp(){
        solo.assertCurrentActivity("Wrong activity", AboutActivity.class);
        List<View> viewList = solo.getCurrentViews();


            //More colde below
    }

    public void tearDown() throws Exception {
        solo.finishOpenedActivities();
      }
}


该测试在solo.getCurrentViews()处引发Null指针异常。

抛出的异常是

java.lang.NullPointerException
at com.jayway.android.robotium.solo.ViewFetcher.getNonDecorViews(ViewFetcher.java:161)
at com.jayway.android.robotium.solo.ViewFetcher.getAllViews(ViewFetcher.java:85)
at com.jayway.android.robotium.solo.ViewFetcher.getViews(ViewFetcher.java:192)
at com.jayway.android.robotium.solo.Solo.getCurrentViews(Solo.java:1477)
at com.example.myproject.test.TestMaindashboard.testSamp(TestMaindashboard.java:36)
at java.lang.reflect.Method.invokeNative(Native Method)
at android.test.InstrumentationTestCase.runMethod(InstrumentationTestCase.java:214)
at android.test.InstrumentationTestCase.runTest(InstrumentationTestCase.java:199)
at android.test.ActivityInstrumentationTestCase2.runTest(ActivityInstrumentationTestCase2.java:192)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:191)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:176)
at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:554)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1701)


有人可以指出我做错了什么吗?谢谢。

最佳答案

您应该将Robotium版本更新为5.1。

关于android - Robotium:getCurrentViews()空指针异常,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/23651094/

10-10 14:30