java.lang.NoSuchMethodError: No static method getFont(Landroid/content/Context;ILandroid/util/Typed

昨天还好好的,今天就报错了,百度谷歌以后,这个错误java中很好整,不过我用kolin开发的项目 修改的时候有点多!不多说,先上完整错误码

java.lang.NoSuchMethodError: No static method getFont(Landroid/content/Context;ILandroid/util/TypedValue;ILandroid/widget/TextView;)Landroid/graphics/Typeface; in class Landroid/support4/content/res/ResourcesCompat; or its super classes (declaration of ‘android.support.v4.content.res.ResourcesCompat’ appears in /data/app/rundi.investment-2/base.apk:classes4.dex)

java解决方法

编译版本和build下的版本号一定要一致,我用的sdk27
compileSdkVersion 27
buildToolsVersion ‘27.0.3’
minSdkVersion 16
targetSdkVersion 27

implementation ‘com.android.support:design:27.1.1’
implementation ‘com.android.support:support-v4:27.1.1’
implementation ‘com.android.support:cardview-v7:27.1.1’
implementation ‘com.android.support:gridlayout-v7:27.1.1’
implementation ‘com.android.support:recyclerview-v7:27.1.1’

对于java代码以上就可以解决 (我百度google都是这样一个答案) 下面我说下kotlin

kotlin解决方法

我之前用的是sdk26,也是按照上面说的都一样,还是报错,就一直找找最后还是无果!
如果是kotlin代码,不仅要一致还要修改代码,因为kotlin一直在升级,如果升级sdk,kotlin也需要跟着改
修改之前 加载布局的代码
override fun onCreateView(inflater: LayoutInflater?, container: ViewGroup?, savedInstanceState: Bundle?): View? {
mView = inflater.inflate(R.layout.fragment_expert_detail,container,false)
return mView
}

我把sdk升级到了27编译版本同上,但是编译完成后会发现好多页面报错,我的是所有加载布局的都报错了,
解决方法
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
mView = inflater.inflate(R.layout.fragment_expert_detail,container,false)
return mView
}

可空的符号?去掉即可 修改过程中不至修改这一个方法,不过都是符号的问题。 祝你们代码无bug

为了便于交流共同学习,博主QQ群543671130(Android学习交流) 欢迎批评指导

猜你喜欢

转载自blog.csdn.net/huangshenshen_/article/details/79990321