首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >robotium nullPointerexception

robotium nullPointerexception
EN

Stack Overflow用户
提问于 2012-11-20 12:45:43
回答 4查看 1.1K关注 0票数 1

我设置了一个测试项目来测试另一个Android项目。一切都很正常。我可以调用solo.clickOnView,测试会运行得很好。当我试图更新一个视图时会发生问题,例如,我想通过调用solo.enterText来更新一个EditText。

Robotium 3.6版

代码语言:javascript
复制
String hello="Hello world"
solo.enterText(myEditText, hello);

我确信myEditText是一个非空对象。运行测试,将出现以下消息

错误消息

代码语言:javascript
复制
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)
EN

回答 4

Stack Overflow用户

发布于 2012-11-23 04:05:57

参见API文档,此方法仅适用于元素的索引。所以如果你想使用id:

代码语言:javascript
复制
String hello="Hello world";
solo.typeText(myEditText, hello);
票数 0
EN

Stack Overflow用户

发布于 2012-11-28 11:05:52

也许实际上没有将myEditText分配给正确的EditText?

代码语言:javascript
复制
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()

票数 0
EN

Stack Overflow用户

发布于 2012-11-28 14:20:02

您可能尚未初始化该对象。只需确保您正在使用的对象已被initialized

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13466736

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档