我已經搜索了一下,但是異常的所有答案都與加載錯誤字體的人有關。TrueType無法在Android蜂巢中加載
但是,我正在嘗試加載TrueType字體。它適用於我測試過的大多數設備。然而,試圖上的Tab 10.1負荷運轉的Android 3.1或的EeePad運行3.2我得到以下異常:
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項目位於「資產/字體/ style_5784.ttf」。 真奇怪的是,它可以在蜂窩以外的所有其他設備上工作。
有沒有人有一個想法可能會導致異常?字體是否可以被破壞,或者可能有文件的名稱那麼簡單?我通過搜索周圍唯一能理解的地方就是它可能是某種程度上被破壞的字體。
這是我的一部分,因此這是一條評論。你有沒有嘗試將字體轉換爲OTF格式,然後加載它?我只有在Android中加載過OTF字體。您可以使用Fontforge,如其常見問題中所述:http://fontforge.sourceforge.net/faq.html –
@AsimIhsan我至少會試一試。 –