2016-09-06 107 views
0

我开始开发xposed模块,但现在出现一个奇怪的错误。 我用RecyclerView无法转换为Xposed上的RecyclerView

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

得到RecyclerView。 card_content是RecyclerView的父级。

我得到这个错误

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

这是没有意义的!与card_content的其他孩子一切工作正常。

预先感谢您!

+0

可能是一个类加载器的问题? http://stackoverflow.com/questions/826319/classcastexception-when-casting-to-the-same-class –

回答

0

@Andrew Sun应该是正确的,我已经在android.support类之前观察过这种模式。

尝试两种类加载器比较:

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

如果他们确实是从不同的类加载器,在card_content.getChildAt(2)和反射使用getClass你应该能够调用它的方法。

+0

是的,这是问题!谢谢 – Materight