天使漫步IT工作室

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


升级了某些组件SDK后,编译可以通过,但是运行期发现报错:

java.lang.NoSuchMethodError: No static method getFont(Landroid/content/Context;ILandroid/util/TypedValue;ILandroid/widget/TextView;)Landroid/graphics/Typeface; in class Landroid/support/v4/content/res/ResourcesCompat; or its super classes (declaration of 'android.support.v4.content.res.ResourcesCompat' appears in /data/app/com.gemdale.decoration-2/base.apk:classes22.dex)
        at android.support.v7.widget.TintTypedArray.getFont(TintTypedArray.java:119)
        at android.support.v7.widget.AppCompatTextHelper.updateTypefaceAndStyle(AppCompatTextHelper.java:208)
        at android.support.v7.widget.AppCompatTextHelper.loadFromAttributes(AppCompatTextHelper.java:110)
        at android.support.v7.widget.AppCompatTextHelperV17.loadFromAttributes(AppCompatTextHelperV17.java:38)
        at android.support.v7.widget.AppCompatEditText.<init>(AppCompatEditText.java:68)
        at android.support.v7.widget.AppCompatEditText.<init>(AppCompatEditText.java:58)
        at android.support.v7.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:112)
        at android.support.v7.app.AppCompatDelegateImplV9.createView(AppCompatDelegateImplV9.java:1024)
        at android.support.v7.app.AppCompatDelegateImplV9.onCreateView(AppCompatDelegateImplV9.java:1081)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:750)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:708)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:839)
        at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:802)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:842)
        at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:802)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:842)
        at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:802)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:519)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:427)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
        at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287)
        at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)

网络上指出,需要引入更高编译版本android SDK才ok,引入后果然成功运行了。

我之前是26,所以升级到sdk = 27

compileSdkVersion 27
buildToolsVersion '27.0.3'
minSdkVersion 16
targetSdkVersion 27
implementation 'com.android.support:support-v4:27.0.2'
implementation 'com.android.support:appcompat-v7:27.0.2'

当前页面是本站的「Baidu MIP」版。查看和发表评论请点击:完整版 »