我设置了一个测试项目来测试另一个Android项目。一切都很正常。我可以调用solo.clickOnView,测试会运行得很好。当我试图更新一个视图时会发生问题,例如,我想通过调用solo.enterText来更新一个EditText。
Robotium 3.6版
String hello="Hello world"
solo.enterText(myEditText, hello);我确信myEditText是一个非空对象。运行测试,将出现以下消息
错误消息
java.lang.NullPointerException
at android.app.Instrumentation.runOnMainSync(Instrumentation.java:338)
at com.jayway.android.robotium.solo.TextEnterer.setEditText(TextEnterer.java:52)
at com.jayway.android.robotium.solo.Solo.enterText(Solo.java:1404)
at com.darakok.test.TestMain.testDisplayBlackBox(TestMain.java:30)
at java.lang.reflect.Method.invokeNative(Native Method)
at android.test.InstrumentationTestCase.runMethod(InstrumentationTestCase.java:204)
at android.test.InstrumentationTestCase.runTest(InstrumentationTestCase.java:194)
at android.test.ActivityInstrumentationTestCase2.runTest(ActivityInstrumentationTestCase2.java:186)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:169)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:154)
at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:520)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1447)发布于 2012-11-23 04:05:57
参见API文档,此方法仅适用于元素的索引。所以如果你想使用id:
String hello="Hello world";
solo.typeText(myEditText, hello);发布于 2012-11-28 11:05:52
也许实际上没有将myEditText分配给正确的EditText?
String hello = "Hello world";
//Based on the ID of the EditText you've given via the layout XML:
EditText myEditText = (EditText) tester.getView(R.id.my_edit_text);
solo.enterText(myEditText, hello);发生这种情况的另一个可能原因是,在整个活动(甚至只是EditText本身)正确加载之前执行的myEditText块。在这种情况下,我建议使用assertCurrentActivity(), sleep() or waitForView()
发布于 2012-11-28 14:20:02
您可能尚未初始化该对象。只需确保您正在使用的对象已被initialized。
https://stackoverflow.com/questions/13466736
复制相似问题