Error getting the font Landroid / content / Context; ILandroid / util / TypedValue

I have a problem with my project. I do not know how to fix this. This is the first time I meet him.

/ UncaughtException: java.lang.NoSuchMethodError: No static GetFont method (Landroid / content / context; ILandroid / Util / TypedValue; ILandroid / widget / TextView;) Landroid / graphic / Font; in the class Landroid / support / v4 / content / res / ResourcesCompat; or its super classes (the declaration 'android.support.v4.content.res.ResourcesCompat' appears in /data/app/codes.trongtin.h.besttrip-2/split_lib_dependencies_apk.apk:classes2.dex)

+8
java android
source share
5 answers

You seem to be using support dependencies. Just run the gradle application so that the version of your build tool matches the 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!

+20
source share

Just change the complieSdkVersion, buildToolsVersion and appCompat options.

  compileSdkVersion 27 buildToolsVersion '27.0.0' implementation 'com.android.support:appcompat-v7:27.0.2' 
+4
source share

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

I will add my installation here along with the Firebase and Glide libraries that I use if it is useful to someone. I saw the error until I reconciled the library versions together with buildToolsVersion and targetSdkVersions.

 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' } 
+3
source share

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

  • Make sure you are using the latest compileSdkVersion 27
  • ALL support libraries must have exactly the same version.
+1
source share

Since you are using a support library, use ResourceCompat

 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); 
0
source share

All Articles