Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Font Family cause NPE on android 26

My App crashes on android 26, my understanding is that it's caused by font-family and support library, but I can't figured out why. On devices below Android 8.0 it work fine.

Caused by: android.view.InflateException: Binary XML file line #0: Error inflating class Button
Caused by: java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at android.support.v4.graphics.TypefaceCompatApi26Impl.addFontFromAssetManager(TypefaceCompatApi26Impl.java:150)
at android.support.v4.graphics.TypefaceCompatApi26Impl.createFromFontFamilyFilesResourceEntry(TypefaceCompatApi26Impl.java:218)
at android.support.v4.graphics.TypefaceCompat.createFromResourcesFamilyXml(TypefaceCompat.java:116)
at android.support.v4.content.res.ResourcesCompat.loadFont(ResourcesCompat.java:249)
at android.support.v4.content.res.ResourcesCompat.loadFont(ResourcesCompat.java:213)
at android.support.v4.content.res.ResourcesCompat.getFont(ResourcesCompat.java:206)
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:152)
at android.support.v7.widget.AppCompatTextHelperV17.loadFromAttributes(AppCompatTextHelperV17.java:38)
at android.support.v7.widget.AppCompatButton.<init>(AppCompatButton.java:77)
at android.support.v7.widget.AppCompatButton.<init>(AppCompatButton.java:67)
at android.support.v7.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:109)
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:772)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:863)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:866)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:866)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
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)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at android.support.v4.graphics.TypefaceCompatApi26Impl.addFontFromAssetManager(TypefaceCompatApi26Impl.java:145)
... 42 more
Caused by: java.lang.NullPointerException
at android.graphics.FontFamily.nAddFontFromAssetManager(Native Method)
at android.graphics.FontFamily.addFontFromAssetManager(FontFamily.java:149)
... 44 more
like image 533
Iaroslav Ternovyi Avatar asked Sep 29 '17 09:09

Iaroslav Ternovyi


People also ask

What is the default font family in Android?

Usage. Roboto is the default font on Android, and since 2013, other Google services such as Google Play, YouTube, Google Maps, and Google Images.


1 Answers

By using only xmlns:app it's work for android v26

<font
    app:font="@font/cuprum_regular"
    app:fontStyle="normal"
    app:fontWeight="400"/>
like image 198
Iaroslav Ternovyi Avatar answered Oct 23 '22 14:10

Iaroslav Ternovyi