1

別の Android プロジェクトをテストするテスト プロジェクトをセットアップします。すべてが正常に機能しています。solo.clickOnView を呼び出すと、テストは正常に実行されます。ビューを更新しようとすると問題が発生します。たとえば、solo.enterText を呼び出して EditText を更新したいとします。

ロボティウム バージョン 3.6

String hello="Hello world"
solo.enterText(myEditText, hello);

myEditText は null 以外のオブジェクトであると確信しています。テストを実行すると、以下のメッセージが表示されます

エラーメッセージ

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)
4

4 に答える 4

0

おそらく、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);

これが発生する別の考えられる理由はmyEditText、アクティビティ全体 (または EditText 自体のみ) が正しく読み込まれる前にブロックが実行された場合です。そのような場合、私はお勧めしますassertCurrentActivity(), sleep() or waitForView()

于 2012-11-28T03:05:51.723 に答える
0

API ドキュメントを参照してください。このメソッドは要素のインデックスでのみ機能します。したがって、id を使用する場合:

String hello="Hello world";
solo.typeText(myEditText, hello);
于 2012-11-22T20:05:56.713 に答える
0

オブジェクトを初期化していない可能性があります。使用しているオブジェクトが 初期化されていることを確認してください。

于 2012-11-28T06:20:02.317 に答える