Espresso ViewPager:尝试在空对象引用上调用虚拟方法'int android.view.KeyEvent.getAction()'



我有一个ViewPager的活动,当我正常使用应用程序时,它工作正常。然而,当我使用它Espresso (JUnit4,使用ActivityTestRule启动的活动)时,每当我尝试调用viewpage . getadapter()时,我都会得到这个错误:

java.lang.NullPointerException: Attempt to invoke virtual method 'int android.view.KeyEvent.getAction()' on a null object reference
    at android.support.v4.view.ViewPager.executeKeyEvent(ViewPager.java:2575)

没有在stacktrace中提到getAdapter(),但是崩溃发生在我调用它的那一刻。

如果我在调试器中暂停一段时间,然后我得到这个崩溃代替:

E/BaseApplication(21357): java.lang.IllegalStateException: No fake drag in progress. Call beginFakeDrag first.
    E/BaseApplication(21357):     at android.support.v4.view.ViewPager.fakeDragBy(ViewPager.java:2417)
    E/BaseApplication(21357):     at com.my.app.ui.common.PagerSlidingTabStrip$1.onGlobalLayout(PagerSlidingTabStrip.java:223)
    E/BaseApplication(21357):     at android.view.ViewTreeObserver.dispatchOnGlobalLayout(ViewTreeObserver.java:912)
    E/BaseApplication(21357):     at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1881)
    E/BaseApplication(21357):     at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1061)
    E/BaseApplication(21357):     at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5885)
    E/BaseApplication(21357):     at android.view.Choreographer$CallbackRecord.run(Choreographer.java:767)
    E/BaseApplication(21357):     at android.view.Choreographer.doCallbacks(Choreographer.java:580)
    E/BaseApplication(21357):     at android.view.Choreographer.doFrame(Choreographer.java:550)
    E/BaseApplication(21357):     at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:753)
    E/BaseApplication(21357):     at android.os.Handler.handleCallback(Handler.java:739)
    E/BaseApplication(21357):     at android.os.Handler.dispatchMessage(Handler.java:95)
    E/BaseApplication(21357):     at android.os.Looper.loop(Looper.java:135)
    E/BaseApplication(21357):     at android.app.ActivityThread.main(ActivityThread.java:5254)
    E/BaseApplication(21357):     at java.lang.reflect.Method.invoke(Native Method)
    E/BaseApplication(21357):     at java.lang.reflect.Method.invoke(Method.java:372)
    E/BaseApplication(21357):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
    E/BaseApplication(21357):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)

我在开发人员选项中禁用了动画

在项目build.gradle dependencies部分从com.android.support:support-v13版本22.0.0更新到22.2.0版本修复了它

相关内容

  • 没有找到相关文章

最新更新