sangmingming / robotium

Automatically exported from code.google.com/p/robotium
0 stars 0 forks source link

solo.enterText(0,var) fails when I pass in a string variable and works when I pass in a sting value #155

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Define a string variable 
     public static final String BIN_ITEM_NUMBER = new String("260833881268");

2. In the test code do the following
            solo.clearEditText(0);
        solo.enterText(0, BIN_ITEM_NUMBER);
        solo.sendKey(Solo.ENTER);

3. You will notice an NPE exception
 java.lang.NullPointerException
 java.lang.RuntimeException: java.lang.NullPointerException
     at com.jayway.android.robotium.solo.Searcher.searchFor(Searcher.java:107)
     at com.jayway.android.robotium.solo.Searcher.searchWithTimeoutFor(Searcher.java:67)
     at com.jayway.android.robotium.solo.Solo.searchText(Solo.java:427)
     at com.mobile.test.BAT.testvalidateItem(BAT.java:79)
     at java.lang.reflect.Method.invokeNative(Native Method)
     at java.lang.reflect.Method.invoke(Method.java:521)
     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 junit.framework.TestCase.runBare(TestCase.java:127)
     at junit.framework.TestResult$1.protect(TestResult.java:106)
     at junit.framework.TestResult.runProtected(TestResult.java:124)
     at junit.framework.TestResult.run(TestResult.java:109)
     at junit.framework.TestCase.run(TestCase.java:118)
     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)
 Caused by: java.lang.NullPointerException
     at java.util.regex.Pattern.compileImpl(Pattern.java:372)
     at java.util.regex.Pattern.<init>(Pattern.java:341)
     at java.util.regex.Pattern.compile(Pattern.java:358)
     at com.jayway.android.robotium.solo.Searcher.searchFor(Searcher.java:133)
     at com.jayway.android.robotium.solo.Searcher.searchFor(Searcher.java:105)

What is the expected output? What do you see instead?
There should be no exception displayed. Rather the variable(BIN_ITEM_NUMBER) 
should be replaced with the defined String value during the runtime for 
solo.enterText();

What version of the product are you using? On what operating system?
robotium-solo-2.5
MAC OS

Please provide any additional information below.
Tests work when I replaced the variable with actual value 
solo.enterText(0,"123456") 

Original issue reported on code.google.com by koneru.s...@gmail.com on 13 Sep 2011 at 11:06

GoogleCodeExporter commented 9 years ago
If you look at the specification of String you will see that what you do is to 
create a string of certain bytes String(byte[] bytes) . What you want to do is 
to assign it a value like:

public static final String BIN_ITEM_NUMBER = "260833881268";

Original comment by renasr...@gmail.com on 14 Sep 2011 at 6:05