Caused by: java.lang.IllegalStateException: Unable to load font ResourceFont(resId=2131034115, weight=FontWeight(weight=400), style=Normal, loadingStrategy=Blocking) at androidx.compose.ui.text.font.FontListFontFamilyTypefaceAdapterKt.firstImmediatelyAvailable(FontListFontFamilyTypefaceAdapter.kt:193)...Caused by: android.content.res.Resources$NotFoundException: Font resource ID #0x7f050003 could not be retrieved. at androidx.core.content.res.ResourcesCompat.loadFont(ResourcesCompat.java:573) at androidx.core.content.res.ResourcesCompat.getFont(ResourcesCompat.java:414)
接着再研究
FontStyle
参数。FontStyle也简单,只有
Normal
和
Italic
两个属性可以用,那应该也不是它们导致的异常了,但是秉着求真的思想,不能放过一条漏网之鱼,还是改了下参数试了试,也证明了确实不是它导致的。
最后就是
FontLoadingStrategy
参数了。
FontLoadingStrategy
是一个
v
alue class
,在它的伴生对象也定义了3个值,分别为
Blocking
,
OptionalLocal
,
Async
。大致含义就是Blocking会阻塞UI线程的去加载字体,OptionalLocal会优先加载本地字体,Async适合加载在线的字体。
Caused by: android.content.res.Resources$NotFoundException: Font resource ID #0x7f050003 could not be retrieved. at androidx.core.content.res.ResourcesCompat.loadFont(ResourcesCompat.java:573) at androidx.core.content.res.ResourcesCompat.getFont(ResourcesCompat.java:414)
public Typeface createFromResourcesFontFile( Context context, Resources resources, int id, String path, int style) {FontFamilyfamily=null;Fontfont=null;try { font = newFont.Builder(resources, id).build(); family = newFontFamily.Builder(font).build();returnnewTypeface.CustomFallbackBuilder(family)// Set font's style to the display style for backward compatibility. .setStyle(font.getStyle()) .build(); } catch (Exception e) {//注意这里捕获了Exception,但是没输出结果。returnnull; }}
没办法,还是单步一步一步的往下执行,执行
family = new
FontFamily.Builder(font).build();
这行代码时程序就异常
闪退了,我们打断点继续往
build
方面里面进。