由于无限循环,Android Jetpack AppCompatTextView.setTypeface StackOverFlowError

时间:2019-03-28 07:14:30

标签: android android-jetpack

我们已经收到一些有关这种情况的崩溃信息:当我们在Android上的AppCompatTextView中使用属性android:textStyle且具有任何值(粗体,斜体或两者)或为android:fontFamily设置值时,在Android上它本身循环的4.2.2版本最终会导致 StackOverFlowError

这是我们如何使用视图的示例。

<androidx.appcompat.widget.AppCompatTextView
        android:id="@+id/welcome_app_name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_weight="3"
        android:gravity="center"
        android:text="@string/app_name"
        android:textColor="#fff"
        android:textSize="26sp"
        android:textStyle="bold" />

这是例外之一:

Caused by java.lang.StackOverflowError
       at java.lang.Class.getDeclaredField(Class.java)
       at java.lang.Class.getDeclaredField(Class.java:629)
       at androidx.core.graphics.TypefaceCompatBaseImpl.getUniqueKey(TypefaceCompatBaseImpl.java:85)
       at androidx.core.graphics.TypefaceCompatBaseImpl.getFontFamily(TypefaceCompatBaseImpl.java:210)
       at androidx.core.graphics.TypefaceCompat.getBestFontFromFamily(TypefaceCompat.java:169)
       at androidx.core.graphics.TypefaceCompat.create(TypefaceCompat.java:196)
       at androidx.appcompat.widget.AppCompatTextView.setTypeface(AppCompatTextView.java:702)
       at android.widget.TextView.setTypeface(TextView.java:1581)
       at androidx.appcompat.widget.AppCompatTextView.setTypeface(AppCompatTextView.java:705)
       at android.widget.TextView.setTypeface(TextView.java:1581)
       at androidx.appcompat.widget.AppCompatTextView.setTypeface(AppCompatTextView.java:705)
       at android.widget.TextView.setTypeface(TextView.java:1581)
       at androidx.appcompat.widget.AppCompatTextView.setTypeface(AppCompatTextView.java:705)
       at android.widget.TextView.setTypeface(TextView.java:1581)
       at androidx.appcompat.widget.AppCompatTextView.setTypeface(AppCompatTextView.java:705)
       at android.widget.TextView.setTypeface(TextView.java:1581)
       at androidx.appcompat.widget.AppCompatTextView.setTypeface(AppCompatTextView.java:705)
       at android.widget.TextView.setTypeface(TextView.java:1581)
       at androidx.appcompat.widget.AppCompatTextView.setTypeface(AppCompatTextView.java:705)
       at android.widget.TextView.setTypeface(TextView.java:1581)
       at androidx.appcompat.widget.AppCompatTextView.setTypeface(AppCompatTextView.java:705)
       at android.widget.TextView.setTypeface(TextView.java:1581)
       at androidx.appcompat.widget.AppCompatTextView.setTypeface(AppCompatTextView.java:705)
       at android.widget.TextView.setTypeface(TextView.java:1581)
       at androidx.appcompat.widget.AppCompatTextView.setTypeface(AppCompatTextView.java:705)
       at android.widget.TextView.setTypeface(TextView.java:1581)
       at androidx.appcompat.widget.AppCompatTextView.setTypeface(AppCompatTextView.java:705)
       at android.widget.TextView.setTypeface(TextView.java:1581)
       at androidx.appcompat.widget.AppCompatTextView.setTypeface(AppCompatTextView.java:705)
       at android.widget.TextView.setTypeface(TextView.java:1581)
       at androidx.appcompat.widget.AppCompatTextView.setTypeface(AppCompatTextView.java:705)
       at android.widget.TextView.setTypeface(TextView.java:1581)
       at androidx.appcompat.widget.AppCompatTextView.setTypeface(AppCompatTextView.java:705)
       at android.widget.TextView.setTypeface(TextView.java:1581)
       at androidx.appcompat.widget.AppCompatTextView.setTypeface(AppCompatTextView.java:705)
       at android.widget.TextView.setTypeface(TextView.java:1581)
       at androidx.appcompat.widget.AppCompatTextView.setTypeface(AppCompatTextView.java:705)
       at android.widget.TextView.setTypeface(TextView.java:1581)
       at androidx.appcompat.widget.AppCompatTextView.setTypeface(AppCompatTextView.java:705)
       at android.widget.TextView.setTypeface(TextView.java:1581)
       at androidx.appcompat.widget.AppCompatTextView.setTypeface(AppCompatTextView.java:705)
       at android.widget.TextView.setTypeface(TextView.java:1581)
       at androidx.appcompat.widget.AppCompatTextView.setTypeface(AppCompatTextView.java:705)
       at android.widget.TextView.setTypeface(TextView.java:1581)
       at androidx.appcompat.widget.AppCompatTextView.setTypeface(AppCompatTextView.java:705)
       at android.widget.TextView.setTypeface(TextView.java:1581)
       at androidx.appcompat.widget.AppCompatTextView.setTypeface(AppCompatTextView.java:705)
       at android.widget.TextView.setTypeface(TextView.java:1581)
       at androidx.appcompat.widget.AppCompatTextView.setTypeface(AppCompatTextView.java:705)
       at android.widget.TextView.setTypeface(TextView.java:1581)
       at androidx.appcompat.widget.AppCompatTextView.setTypeface(AppCompatTextView.java:705)
       at android.widget.TextView.setTypeface(TextView.java:1581)
       at androidx.appcompat.widget.AppCompatTextView.setTypeface(AppCompatTextView.java:705)
       at android.widget.TextView.setTypeface(TextView.java:1581)
       at androidx.appcompat.widget.AppCompatTextView.setTypeface(AppCompatTextView.java:705)
       at android.widget.TextView.setTypeface(TextView.java:1581)
       at androidx.appcompat.widget.AppCompatTextView.setTypeface(AppCompatTextView.java:705)
       at android.widget.TextView.setTypeface(TextView.java:1581)
       at androidx.appcompat.widget.AppCompatTextView.setTypeface(AppCompatTextView.java:705)
       at android.widget.TextView.setTypeface(TextView.java:1581)
       at androidx.appcompat.widget.AppCompatTextView.setTypeface(AppCompatTextView.java:705)
       at android.widget.TextView.setTypeface(TextView.java:1581)
       at androidx.appcompat.widget.AppCompatTextView.setTypeface(AppCompatTextView.java:705)
       at android.widget.TextView.setTypeface(TextView.java:1581)

// it goes on like this forever until it reaches to Activity.setContentView()

甚至可能在某些特定设备上也是如此,因为我们无法在本地重现此问题。 除了删除文字样式之外,可以采取什么措施解决此问题?谢谢您的帮助。

0 个答案:

没有答案