This is the code for motion events in my instrumentation testing.
long downTime = SystemClock.uptimeMillis();
long eventTime = SystemClock.uptimeMillis();
MotionEvent event = MotionEvent.obtain(downTime, eventTime,
MotionEvent.ACTION_DOWN, 100,100, 0);
MotionEvent event2 = MotionEvent.obtain(downTime, eventTime,
MotionEvent.ACTION_UP, 100, 100, 0);
instrumentation.sendPointerSync(event);
instrumentation.sendPointerSync(event2);
And the following is the error iam getting:
java.lang.NullPointerException
at com.ni.fastflip.test.FastFlipWebviewTest.test(FastFlipWebviewTest.java:28)
at java.lang.reflect.Method.invokeNative(Native Method)
at android.test.InstrumentationTestCase.runMethod(InstrumentationTestCase.java:205)
at android.test.InstrumentationTestCase.runTest(InstrumentationTestCase.java:195)
at android.test.ActivityInstrumentationTestCase2.runTest(ActivityInstrumentationTestCase2.jav开发者_JAVA百科a:175)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:169)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:154)
at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:430)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1447)
Can any body suggest me what to do please
You have to do android.app.Instrumentation inst = getInstrumentation();
Inside ActivityInstrumentationTestCase2
before sending pointer syncs or other classes, which have possibility to retrieve instruments instance.
Complete sample here
Which ones of these lines is line 28? thats where the null pointer exep was.
Use
if(whatever==null){ Log.d("tag","whatever was null"); }
to figure out which reference was null on line 28 if you have to.
If the top of the stack trace indicates the null pointer is on this line:
instrumentation.sendPointerSync(event);
Then that means that instrumentation
is null, not event
. If event was null then the null pointer would happen inside of the sendPointerSync
method or further up the stack.
精彩评论