question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[TextView] Crash when using custom style

See original GitHub issue

Description: I am facing a crash at TextView after update my Material Android Library to version 1.2.0 from 1.1.0. Error Code:

Error inflating class TextView
Caused by: java.lang.IllegalArgumentException: Font {path=null, style=FontStyle { weight=400, slant=0}, ttcIndex=0, axes=, localeList=, buffer=java.nio.DirectByteBuffer[pos=0 lim=433584 cap=433584]} has already been added

Source code: This is my TextView element.

<TextView
    android:id="@+id/dashboardMessageTV"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="#FFF3EF"
    android:drawableStart="@drawable/ic_info"
    android:drawablePadding="4dp"
    android:gravity="start|center_vertical"
    android:paddingStart="4dp"
    android:paddingTop="8dp"
    android:paddingEnd="4dp"
    android:paddingBottom="8dp"
    android:textAlignment="gravity"
    android:textAppearance="@style/CustomTextParagraph"
    android:visibility="gone"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent" />

And this is my CustomTextParagraph style.

<style name="CustomTextParagraph" parent="@android:style/TextAppearance.Small">
    <item name="android:textStyle">normal</item>
    <item name="android:fontFamily">@font/sf_pro</item>
    <item name="android:textColor">@color/darkGray</item>
</style>

This is my theme parent.

<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">

Android API version: Android 10 (API level 29)

Material Library version: implementation 'com.google.android.material:material:1.2.0'

Device: Xiao Mi 9

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
gabrielemariotticommented, Aug 6, 2020

Check your @font/sf_pro.

This kind of error in shown when you try to register multiple fonts with the same style and weight into the same font family (and it is related to androidx.core version 1.2.0 and higher).

2reactions
gabrielemariotticommented, Aug 8, 2020

The issue should be here because both font elements have the same values for the fontStyle and fontWeight:

    <font
        app:font="@font/sf_pro_regular"
        app:fontStyle="normal"
        app:fontWeight="400" />
    <font
        app:font="@font/sf_pro_medium"
        app:fontStyle="normal"
        app:fontWeight="400" />
Read more comments on GitHub >

github_iconTop Results From Across the Web

Why the app crashes, when I trying to set a text size attribute ...
When I trying to apply a custom style to my TextView , and trying to specify the textSize attribute not via value in...
Read more >
Problems with themes and attributes when build running app ...
Description: The main issue I would like to report is that the app crashes when it tires to use a custom attribute in...
Read more >
Spans | Android Developers
Spans are powerful markup objects that you can use to style text at a ... You can also create your own spans to...
Read more >
Xcode 11 crashes while using attri… | Apple Developer Forums
Xcode is crashing every time I try to click on the text field of a text view or button after switching Title to...
Read more >
Underspanding spans - Medium
2. Text style changes by adding/removing spans · textView.setText(CharSequence) two times: first to set the initial text and then again when the button...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found