“本地字体无法制作”仅适用于某些人

我有一个可以更改某些元素字体字体的应用程序。它对大多数人来说效果很好,但是尝试更改字体时可能会有0.5%的异常。堆栈跟踪的重要部分是:


Caused by: java.lang.RuntimeException: native typeface cannot be made

at android.graphics.Typeface.<init>(Typeface.java:147)

at android.graphics.Typeface.createFromAsset(Typeface.java:121)

正如我所说的,它对大多数人都有效,所以我认为这与字体文件或代码无关。关于如何解决这个问题的任何建议?


编辑:这是我的代码:


Typeface phoneticFont = Typeface.createFromAsset(getAssets(),

                                                 "fonts/CharisSILR.ttf");

TextView tv;

tv = ((TextView) findViewById(R.id.searchPronunciationTitle));

tv.setTypeface(phoneticFont);


偶然的你
浏览 384回答 3
3回答

小唯快跑啊

我遵循了此处找到的一些解决方案,但没有成功。我认为它确实像程序员经常做的那样晦涩难懂。然后在我读过的某处可能与字体路径有关,即:代替:Typeface phoneticFont = Typeface.createFromAsset(getAssets(),&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;"blanch_caps.ttf");&nbsp; &nbsp;我改为:Typeface phoneticFont = Typeface.createFromAsset(getAssets(),&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;"fonts/blanch_caps.ttf");&nbsp; &nbsp;我的文件在assets / fonts / blanch_caps.ttf中。不是它像魅力一样起作用!

慕村9548890

我为此付出了很多努力。我尝试了所有可能性,没有任何帮助。最后,问题出在其他地方。如果您正在使用Gradle构建项目,请不要忘记在build.gradle文件中添加这些行。这解决了我的问题。&nbsp; &nbsp; sourceSets {&nbsp; &nbsp; main {&nbsp; &nbsp; &nbsp; &nbsp; assets.srcDirs = ['assets']&nbsp; &nbsp; }}
打开App,查看更多内容
随时随地看视频慕课网APP