Android Robolectric错误org.fest.reflect.exception.ReflectionError:找不到方法“$$robo$getData”

Android Robolectric错误org.fest.reflect.exception.ReflectionError:找不到方法“$$robo$getData”,android,eclipse,ant,junit,robolectric,Android,Eclipse,Ant,Junit,Robolectric,当我写作的时候 @Before public void setUp() throws Exception { Activity activity = Robolectric.buildActivity(ActivityMain.class).create().get(); } 在运行测试之后,它给了我一个错误org.fest.reflect.exception.ReflectionError:找不到方法“$$robo$getData”,我正在使用eclipse和

当我写作的时候

@Before
    public void setUp() throws Exception {
       Activity activity = Robolectric.buildActivity(ActivityMain.class).create().get();

    }
在运行测试之后,它给了我一个错误org.fest.reflect.exception.ReflectionError:找不到方法“$$robo$getData”,我正在使用eclipse和ant build来测试android的机器人分子测试

但这段代码在我的测试中运行良好

@Test
    public void testBasicResourceValue() throws Exception {
        String helloFromActivity = new ActivityMain().getResources().getString(R.string.str_my_file);
       assertThat(helloFromActivity, equalTo("newfile"));
    }
因此,它确认程序能够获取AndroidManifest.xml

活动= Robolectric.buildActivityActivityMain.class.create.get;这 line不支持ANT构建我不知道为什么?我听说 robolectric不再支持ANT了,所以我找到了另一个解决方法 对于此问题,请使用 此代码如下所示

 @Before
    public void setUp() throws Exception {
      MyActivity  activity = new MyActivity();
      //Remember setContentView() has to call before you are trying to get any resource ID from the activity like Button,TextView etc other wise you will get the not shadow object for those views.
        activity.setContentView(R.layout.warning);
        Assert.assertNotNull(activity);

    }