TrueType 在 Android 蜂巢中加载失败
我进行了一些搜索,但有关异常的所有答案都与人们加载错误的字体有关。
但是,我正在尝试加载 TrueType 字体。它适用于我测试过的大多数设备。但是,当尝试在运行 Android 3.1 的 Tab 10.1 或运行 3.2 的 EEEPad 上加载时,我收到以下异常:
Caused by: java.lang.RuntimeException: native typeface cannot be made
完整的堆栈跟踪:
java.lang.RuntimeException: Unable to start activity ComponentInfo{se.healthyheroes.android.app/se.healthyheroes.android.app.LoginActivity}: java.lang.RuntimeException: native typeface cannot be made
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1815)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1831)
at android.app.ActivityThread.access$500(ActivityThread.java:122)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1024)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:132)
at android.app.ActivityThread.main(ActivityThread.java:4123)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:491)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
at dalvik.system.NativeStart.main(Native Method)
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)
at se.healthyheroes.android.app.LoginActivity.initViews(LoginActivity.java:154)
at se.healthyheroes.android.app.LoginActivity.onCreate(LoginActivity.java:94)
at android.app.Activity.performCreate(Activity.java:4397)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1048)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1779)
... 11 more
java.lang.RuntimeException: native typeface cannot be made
at android.graphics.Typeface.<init>(Typeface.java:147)
at android.graphics.Typeface.createFromAsset(Typeface.java:121)
at se.healthyheroes.android.app.LoginActivity.initViews(LoginActivity.java:154)
at se.healthyheroes.android.app.LoginActivity.onCreate(LoginActivity.java:94)
at android.app.Activity.performCreate(Activity.java:4397)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1048)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1779)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1831)
at android.app.ActivityThread.access$500(ActivityThread.java:122)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1024)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:132)
at android.app.ActivityThread.main(ActivityThread.java:4123)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:491)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
at dalvik.system.NativeStart.main(Native Method)
您可能想知道 LoginActivity 中的第 154 行。 该行是这一行:
Typeface tf =(Typeface.createFromAsset(getAssets(), "fonts/style_5784.ttf"));
该字体位于我的 Eclipse 项目中的“assets/fonts/style_5784.ttf”下。 真正奇怪的是它可以在除 honeycomb 之外的所有其他设备上运行。
有谁知道什么可能导致异常?字体是否已损坏,或者是否有像文件名这样简单的内容?通过四处搜索,我唯一明白的是,它可能是字体以某种方式损坏了。
I have searched a bit but all the answers on the exception is related to people loading the wrong font.
However, I am trying to load a TrueType font. It works for the majority of the devices I have tested on. However, when trying to load on the Tab 10.1 running Android 3.1 or EEEPad running 3.2 I get the following exception:
Caused by: java.lang.RuntimeException: native typeface cannot be made
The complete stack trace:
java.lang.RuntimeException: Unable to start activity ComponentInfo{se.healthyheroes.android.app/se.healthyheroes.android.app.LoginActivity}: java.lang.RuntimeException: native typeface cannot be made
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1815)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1831)
at android.app.ActivityThread.access$500(ActivityThread.java:122)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1024)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:132)
at android.app.ActivityThread.main(ActivityThread.java:4123)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:491)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
at dalvik.system.NativeStart.main(Native Method)
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)
at se.healthyheroes.android.app.LoginActivity.initViews(LoginActivity.java:154)
at se.healthyheroes.android.app.LoginActivity.onCreate(LoginActivity.java:94)
at android.app.Activity.performCreate(Activity.java:4397)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1048)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1779)
... 11 more
java.lang.RuntimeException: native typeface cannot be made
at android.graphics.Typeface.<init>(Typeface.java:147)
at android.graphics.Typeface.createFromAsset(Typeface.java:121)
at se.healthyheroes.android.app.LoginActivity.initViews(LoginActivity.java:154)
at se.healthyheroes.android.app.LoginActivity.onCreate(LoginActivity.java:94)
at android.app.Activity.performCreate(Activity.java:4397)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1048)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1779)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1831)
at android.app.ActivityThread.access$500(ActivityThread.java:122)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1024)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:132)
at android.app.ActivityThread.main(ActivityThread.java:4123)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:491)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
at dalvik.system.NativeStart.main(Native Method)
You might wonder about line 154 in LoginActivity.
The line is this one:
Typeface tf =(Typeface.createFromAsset(getAssets(), "fonts/style_5784.ttf"));
The font is located under "assets/fonts/style_5784.ttf" in my project in Eclipse.
The really weird thing is that it works on all the other devices except honeycomb.
Does anyone have an idea what could cause the exception? Could the font be broken or perhaps there is something as simple as the name of the file? The only thing I managed to understand by searching around for it is that it could be the font that is broken somehow.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
进一步查看此错误后,该错误似乎不是由字体名称引起的。该错误发生在本机代码内部,该代码很可能在 Honeycomb 中发生更改,并且无法通过堆栈跟踪进行调试。
在源代码发布之前,我们将无法进一步调查该错误。
Upon looking further into this error it doesn't look like the error is being causing by the font name. The error is occurring inside of native code which is most likely changed in Honeycomb and cannot be debugged through a stack trace.
Until the source has been released we will not be able to look further into the error.