Error get Font Landroid/content/Context;ILandroid/util/TypedValue

匿名 (未验证) 提交于 2019-12-03 08:36:05

问题:

I have problem with my project. I don't know how to fix it. This is first time I meet it.

/UncaughtException: 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/codes.trongtin.h.besttrip-2/split_lib_dependencies_apk.apk:classes2.dex)

回答1:

It seems you are using support dependencies. Just check in your app gradle that your build tools version is the same as support versions.

For example:

android { ...     buildToolsVersion "26.0.2" ... } 

and

dependencies { ...     compile 'com.android.support:support-v4:26.0.2'     compile 'com.android.support:appcompat-v7:26.0.2'     compile 'com.android.support:recyclerview-v7:26.0.2'     compile 'com.android.support:support-v13:26.0.2' ... } 

must have the same version.

It worked for me!



回答2:

Just Change complieSdkVersion, buildToolsVersion and appCompat dependency.

      compileSdkVersion 27       buildToolsVersion '27.0.0'        implementation 'com.android.support:appcompat-v7:27.0.2' 


回答3:

Thanks @agustin-ruiz-linares for the correct answer.

I'll add my setup here along with the Firebase and Glide libraries that I'm using in case its helpful for someone. I was seeing the error until I reconciled the library versions along with the buildToolsVersion and targetSdkVersions, too.

android {     compileSdkVersion 27     defaultConfig {         minSdkVersion 20         targetSdkVersion 27         buildToolsVersion "27.0.2"     } }  dependencies {     implementation fileTree(dir: 'libs', include: ['*.jar'])     implementation 'com.android.support:appcompat-v7:27.0.2'     implementation 'com.android.support:design:27.0.2'     implementation 'com.android.support.constraint:constraint-layout:1.0.2'     implementation 'com.google.firebase:firebase-database:11.8.0'     implementation 'com.google.firebase:firebase-storage:11.8.0'     implementation 'com.firebaseui:firebase-ui-database:3.2.1'     implementation 'com.github.bumptech.glide:glide:4.5.0'     annotationProcessor 'com.github.bumptech.glide:compiler:4.5.0'     implementation 'com.android.support:support-v4:27.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' } 


回答4:

This error happen if there is a mismatch in version of any support dependency . 2 things to consider to avoid this error:

  1. Make sure you are using the Latest version of compileSdkVersion 27
  2. ALL the support libraries should be of exactly same version


回答5:

Since you are using support library, Use ResourcesCompat

Typeface typeFace= ResourcesCompat.getFont(getActivity(),R.font.roboto); 

This will fix your problem.

If you want to support api level 26 and above you can use

Typeface typeface = getResources().getFont(R.font.myfont); 


回答6:

The solution is very simple ..just change build tool version to 27.0.2 and all supports library to 27.0.2

Done. Bingo!



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!