1

I started to develop an xposed module but now I get a strange error. I used

RecyclerView player_recycler_view=(RecyclerView)card_content.getChildAt(2)

to get the RecyclerView. card_content is the parent of the RecyclerView.

I get this error

java.lang.ClassCastException: android.support.v7.widget.RecyclerView cannot be cast to android.support.v7.widget.RecyclerView

It makes no sense! With the others child of card_content everything is working fine.

Thank you in advance!

materight
  • 527
  • 8
  • 22
  • Could be a classloader issue? http://stackoverflow.com/questions/826319/classcastexception-when-casting-to-the-same-class – Andrew Sun Sep 07 '16 at 23:09
  • Possible duplicate of [ClassCastException when casting to the same class](https://stackoverflow.com/questions/826319/classcastexception-when-casting-to-the-same-class) – KYHSGeekCode Aug 03 '18 at 12:42

1 Answers1

1

@Andrew Sun should be correct, I have observed this pattern before for android.support classes.

Try to compare both classloaders:

if (RecyclerView.class.getClassLoader() == card_content.getChildAt(2).getClass().getClassLoader()) {
    Log.v(TAG, "Same classloader");
} else {
    Log.v(TAG, "Another classloader");
}

If they are indeed from different class loaders, using getClass on the card_content.getChildAt(2) and reflection you should be able to invoke on its methods.

4knahs
  • 629
  • 4
  • 14