RecyclerView使用时版本不兼容问题解决

来源:互联网 发布:矩阵理论 张跃辉答案 编辑:程序博客网 时间:2024/05/20 19:16

RecyclerView使用时版本不兼容问题解决

Fragment 中使用RecyclerView时,报错如下:

recordTbsCrash:{java.lang.NoSuchMethodError: No static method getDisplay(Landroid/view/View;)Landroid/view/Display; in class Landroid/support/v4/view/ViewCompat; or its super classes (declaration of 'android.support.v4.view.ViewCompat' appears in /data/app/*/base.apk:classes8.dex)

解决办法:
1. 检查v4包和v7包 版本是否统一
2. 如引用的包较多,app的gradle文件中添加如下:

android {...    configurations {        all*.exclude group: 'com.android.support', module: 'support-v4'        all*.exclude group: 'com.android.support', module: 'support-annotations'    } }
  1. 如果人不能解决,检查appcompat 是否引入正确,如:
dependencies {    compile 'com.android.support:appcompat-v7:25.3.1'    compile 'com.android.support:recyclerview-v7:25.3.1'}

“com.android.support:appcompat-v7:25.3.1” 包一定要引入,Fragment等基础组件需要,否则会报错。

原创粉丝点击