“RuntimeException: native typeface cannot be made” when loading font

↘锁芯ラ 提交于 2019-11-27 19:57:22
CommonsWare

Android does not support OpenType (OTF), only TrueType (TTF), so your Molot.otf font probably will not work. I wrote both of those blog posts you link to in your opening sentence (the one is a pirated copy of the other), and they do not use Molot.otf.

(BTW, I somewhat repaired the formatting of that post -- AndroidGuys keeps changing WordPress hosts, and so my older posts are terribly broken in terms of formatting).

EDIT: As stated in the comments, Android DOES now support OTF.

phuongnv

I also get the same error and I have solution follow.

Typeface tf = Typeface.createFromAsset(getAssets(), "fonts/Molot.otf")

you must put fonts/Molot.otf in assets/fonts folder in your Eclipse.

after you can Run it.

if you can not Run it successfull you can send proplem via

mamuso

Unfortunately, the typeface cannot be made error is not very specific, and it can be the result of many things going wrong. It's important to check for two things:

  • The first and most important: The file is found!
  • The font is valid in your device.

The best way is to change your font file for a known valid font file.
If it fails, then it's the first problem.
If not, it's the second, so you will have to deal with FontForge or look for another font.

check font's name and extension. it is case sensitive & probably all caps. eg.

Typeface tf = Typeface.createFromAsset(getAssets(), "fonts/MOLOT.OTF")

FYI. My reason for the crash is some reason caused by Eclipse. All I did is just cleaning the project and ran again, then it works.

Firstly, I tried the custom font in my test project which I use to try some new functions.It worked on the very first time. But it didn't work on the project i'm working on until I did as above.

So try as many methods as you can.

Android does support OTF files for Typefaces, if you're facing this problem, make sure that you're setting the right path for the font.put font into folder fonts inside assets folder and create the typeface as below :

Typeface typeface = Typeface.createFromAsset(getAssets(), "font/StencilStd.otf");
TextView text = (TextView) findViewById(R.id.textView);
text.setTypeface(typeface);
user1693108

@deng his answer worked for me":

check font's name and extension. it is case sensitive & probably all caps. eg.

Typeface tf = Typeface.createFromAsset(getAssets(), "fonts/MOLOT.OTF")

You should edit your font with 'Fontlab' Software in binary mod.

Android does support OTF files for Typefaces, if you're facing this problem, make sure that you're setting the right path for the font, for example, if you have the file fontname.otf, put it in a folder fonts inside assets folder and create the typeface like follows :

Typeface typeface = Typeface.createFromAsset(getAssets(), "fonts/fontname.otf");

(path argument should not start with "/") and the file name should not include special characters or a "-" and should be in lowercases

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!