我在更新最新的firebase时遇到了这个错误(java.lang.NoSuchMethodError:没有静态方法getFont)

时间:2018-02-18 05:22:32

标签: java android android-studio

buildscript {

    repositories {
        apply plugin: 'announce'
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.1'
        classpath 'com.google.gms:google-services:3.1.1'


        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories 
    {
        google()
        jcenter()
        maven{ url "https://jitpack.io"}
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

App Gradle(可能是错误的原因)

apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    defaultConfig {
        applicationId "chocolahat.softeng.sweetbitescafe"
        minSdkVersion 21
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:26.+'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'

    // my Library
    implementation 'com.google.firebase:firebase-core:11.6.2'

    implementation 'com.google.firebase:firebase-database:11.6.2'

    implementation 'com.android.support:cardview-v7:26.+'

    implementation 'com.android.support:recyclerview-v7:26.+'

    implementation 'com.squareup.picasso:picasso:2.5.2'

    implementation 'com.firebaseui:firebase-ui-database:3.1.2'

    implementation 'com.cepheuen.elegant-number-button:lib:1.0.2'

    implementation 'com.android.support:design:26.+'

    implementation 'com.amulyakhare:com.amulyakhare.textdrawable:1.0.1'

    implementation 'com.readystatesoftware.sqliteasset:sqliteassethelper:+'

    implementation 'com.google.android.gms:play-services-location:11.6.2'

    implementation 'com.github.mancj:MaterialSearchBar:0.7.1'

    implementation 'com.github.d-max:spots-dialog:0.7@aar'

}
apply plugin: 'com.google.gms.google-services'

错误(不幸的是app停止了)

  

E / AndroidRuntime:致命异常:主要                         过程:chocolahat.softeng.sweetbitescafe,PID:26876                         java.lang.NoSuchMethodError:没有静态方法getFont(Landroid / content / Context; ILandroid / util / TypedValue; ILandroid / widget / TextView;)Landroid / graphics / Typeface;在课堂上Landroid / support / v4 / content / res / ResourcesCompat;或其超级类('android.support.v4.content.res.ResourcesCompat'的声明出现在/data/app/chocolahat.softeng.sweetbitescafe-2/split_lib_dependencies_apk.apk)                             在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)                             在android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:725)                             在android.view.LayoutInflater.rInflate(LayoutInflater.java:806)                             在android.view.LayoutInflater.rInflate(LayoutInflater.java:809)                             在android.view.LayoutInflater.inflate(LayoutInflater.java:504)                             在android.view.LayoutInflater.inflate(LayoutInflater.java:414)                             在android.view.LayoutInflater.inflate(LayoutInflater.java:365)                             在android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287)                             在android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)                             at chocolahat.softeng.sweetbitescafe.MainActivity.onCreate(MainActivity.java:18)                             在android.app.Activity.performCreate(Activity.java:6092)                             在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1112)                             在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2481)                             在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2608)                             在android.app.ActivityThread.access $ 800(ActivityThread.java:178)                             在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1470)                             在android.os.Handler.dispatchMessage(Handler.java:111)                             在android.os.Looper.loop(Looper.java:194)                             在android.app.ActivityThread.main(ActivityThread.java:5637)                             at java.lang.reflect.Method.invoke(Native Method)                             在java.lang.reflect.Method.invoke(Method.java:372)                             在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:959)                             在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:754)

MainActivity.java:18行代码就是这个的setContentView(R.layout.activity_main);

请解决:(

1 个答案:

答案 0 :(得分:0)

Api等级26已经出现其默认的font属性。并且相同的字体属性可能已在代码中定义为部分custom font attribute

解决方案:更改自定义字体属性名称。

fontcustom_font一样,在xml文件中用作custom_font:

同样的更改也将应用于您的Java代码中。