java.lang.NoSuchMethodError:没有静态方法getFont

时间:2017-12-06 11:31:15

标签: android textview android-support-library calligraphy

我正在使用ChrisJenx的Calligraphy Library。突然间,今天早上我的项目开始抛出奇怪的错误。有人对此有任何想法吗?我也试过看 TintTypedArray.java:119 。 gradle缓存中的一个有getFont方法,即v26.0.2,但在sdk / extras中没有,这是v25.3.1。我认为gradle缓存代码将用于此但仍然是抛出错误。请帮忙。

logcat的:

  

12-06 16:52:40.516 18533-18533 / com.nabta E / AndroidRuntime:FATAL   例外:主要                                                                  过程:com.nabta,PID:18533                                                                  java.lang.NoSuchMethodError:没有静态方法   的getFont(Landroid /内容/上下文; ILandroid / util的/的TypedValue; ILandroid /插件/ TextView的)Landroid /图形/字体或符号;   在课堂上Landroid / support / v4 / content / res / ResourcesCompat;或者它的超级   课程(宣言)   ' android.support.v4.content.res.ResourcesCompat'出现在   /data/app/com.nabta-2/base.apk:classes13.dex)                                                                      在android.support.v7.widget.TintTypedArray.getFont(TintTypedArray.java:119)                                                                      在android.support.v7.widget.AppCompatTextHelper.updateTypefaceAndStyle(AppCompatTextHelper.java:208)                                                                      在android.support.v7.widget.AppCompatTextHelper.loadFromAttributes(AppCompatTextHelper.java:110)                                                                      在android.support.v7.widget.AppCompatTextHelperV17.loadFromAttributes(AppCompatTextHelperV17.java:38)                                                                      在android.support.v7.widget.AppCompatTextView。(AppCompatTextView.java:81)                                                                      在android.support.v7.widget.AppCompatTextView。(AppCompatTextView.java:71)                                                                      在android.support.v7.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:103)                                                                      在android.support.v7.app.AppCompatDelegateImplV9.createView(AppCompatDelegateImplV9.java:1024)                                                                      在android.support.v7.app.AppCompatDelegateImplV9.onCreateView(AppCompatDelegateImplV9.java:1081)                                                                      at uk.co.chrisjenx.calligraphy.CalligraphyLayoutInflater $ WrapperFactory2.onCreateView(CalligraphyLayoutInflater.java:280)                                                                      在android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:776)                                                                      在android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:734)                                                                      在android.view.LayoutInflater.rInflate(LayoutInflater.java:865)                                                                      在android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:828)                                                                      在android.view.LayoutInflater.rInflate(LayoutInflater.java:873)                                                                      在android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:828)                                                                      在android.view.LayoutInflater.inflate(LayoutInflater.java:525)                                                                      at uk.co.chrisjenx.calligraphy.CalligraphyLayoutInflater.inflate(CalligraphyLayoutInflater.java:60)                                                                      在android.view.LayoutInflater.inflate(LayoutInflater.java:427)                                                                      在android.view.LayoutInflater.inflate(LayoutInflater.java:378)                                                                      在android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287)                                                                      在android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)                                                                      在com.nabta.activity.MainActivity.onCreate(MainActivity.java:47)                                                                      在android.app.Activity.performCreate(Activity.java:6977)                                                                      在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1126)                                                                      在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2946)                                                                      在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3064)                                                                      在android.app.ActivityThread.-wrap14(ActivityThread.java)                                                                      在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1659)                                                                      在android.os.Handler.dispatchMessage(Handler.java:102)                                                                      在android.os.Looper.loop(Looper.java:154)                                                                      在android.app.ActivityThread.main(ActivityThread.java:6816)                                                                      at java.lang.reflect.Method.invoke(Native Method)                                                                      在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:1563)                                                                      在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1451)

3 个答案:

答案 0 :(得分:2)

我解决了这个错误。运行studio 3.0.0后,我遇到了这个bug。根据此处的建议升级构建工具版本解决了它:https://stackoverflow.com/a/47126127/3484668

答案 1 :(得分:2)

就我而言,我在 Kotlin 项目中使用 Android-KTX implementation 'androidx.core:core-ktx:0.1',这就是错误的原因。我刚刚将其从 build.gradle 中删除为依赖项。

P.S我的帖子的答案相同: java.lang.NoSuchMethodError: No static method getFont(Landroid/content/Context;ILandroid/util/TypedValue;ILandroid/widget/TextView;)

答案 2 :(得分:0)

更新构建gradle对我有用。

compileSdkVersion 27

targetSdkVersion 27

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:27.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.2'
    implementation 'com.android.support:recyclerview-v7:27.0.0'
    implementation 'com.android.support:cardview-v7:27.0.0'
}