ksoichiro / Android-ObservableScrollView

Android library to observe scroll events on scrollable views.
http://ksoichiro.github.io/Android-ObservableScrollView/
Apache License 2.0
9.66k stars 2.07k forks source link

android.view.ViewRootImpl cannot be cast to android.view.View #94

Open KevinColemanInc opened 9 years ago

KevinColemanInc commented 9 years ago

Any ideas why I am I getting this error? Running version 1.5.0

  java.lang.ClassCastException: android.view.ViewRootImpl cannot be cast to android.view.View
        at com.github.ksoichiro.android.observablescrollview.ObservableRecyclerView.onTouchEvent(ObservableRecyclerView.java:227)
        at android.view.View.dispatchTouchEvent(View.java:7706)
        at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2210)
        at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1945)
        at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
        at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959)
        at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
        at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959)
        at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
        at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959)
        at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
        at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959)
        at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
        at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959)
        at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
        at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959)
        at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
        at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959)
        at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
        at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959)
        at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
        at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959)
        at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
        at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959)
        at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:2068)
        at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1515)
        at android.app.Activity.dispatchTouchEvent(Activity.java:2458)
        at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:2016)
        at android.view.View.dispatchPointerEvent(View.java:7886)
        at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:3947)
        at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:3826)
        at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3392)
        at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3442)
        at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3411)
        at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3518)
        at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3419)
        at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:3575)
        at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3392)
        at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3442)
        at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3411)
        at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3419)
        at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3392)
        at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:5532)
        at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:5512)
        at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:5483)
        at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:5612)
        at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:185)
        at android.view.InputEventReceiver.nativeConsumeBatchedInputEvents(Native Method)
        at android.view.InputEventReceiver.consumeBatchedInputEvents(InputEventReceiver.java:176)
        at android.view.ViewRootImpl.doConsumeBatchedInput(ViewRootImpl.java:5585)
        at android.view.ViewRootImpl$ConsumeBatchedInputRun

edit: seems to happen when I scroll down on a recyclerview that is smaller than the screen (aka, no scrolling necessary)

KevinColemanInc commented 9 years ago

I grabbed the source code and I did this in ObservableRecyclerView.java:227:

  for (View v = this; v != null && v != parent; ) {
      ViewParent temp = v.getParent();
      if (temp instanceof View) {
          v = (View) temp;
          offsetX += v.getLeft() - v.getScrollX();
          offsetY += v.getTop() - v.getScrollY();
      }
      else
      {break;}
  }

and it seemed to fix it.

mobiRic commented 8 years ago

I stumbled across this post when searching on the same bug. Turns out it has been around for a while, and is logged with google here:

In case that helps you guys, or any future readers.