Android: Custom Font setup exception

I hit my head by setting custom fonts to text from code from one hour. I already did this in my previous project and it worked!

But I don’t know for what reason, this gives me the exhaustion of “native font cannot be created” here. I looked at a lot of SO questions related to this, and tried to come up with a solution and worked on those cases. But none of them work for me. :(

I deleted and updated the assests folder, and also tried with another font.ttf file in accordance with the answers to a question related to the same problems. I also cleaned and rebuilt the project, but all efforts were in vain!

Please help me! I would be grateful for your help.

The code I use to install fonts:

I have my GOTHIC.TTF fonts in the resource folder:

... Typeface font=Typeface.createFromAsset(getAssets(), "fonts/GOTHIC.TTF"); title.setTypeface(font); ... 

EDIT:

I think I was mistaken by writing "fonts / GOTHIC.TTF", where when I inserted fonts directly into assets, and not into assets / fonts. But to do this "GOTHIC.TTF" also does not solve the problem. Where can I go wrong ?!

+4
source share
3 answers

I don’t know what exactly worked from everything that I tried, but I did it! :)

All I tried was to close eclipse and immulator.Re-opening the project, cleaning it up and then fixing another error of my project led me to work.

Thanks for helping all the guys !!

0
source

Where do fonts fit and are they referenced correctly?

example:

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

you should put fonts / myfont.otf in the assets / fonts folder in your Eclipse.

cm.:
"RuntimeException: native font cannot be created" when loading a font

+3
source

Make sure the font extension is lowercase. In other words, it should not be

GOTHIC.TTF

but

GOTHIC.ttf

Also try specifying it in the font folder in assets and referring to it using fonts/GOTHIC.TTF

0
source

Source: https://habr.com/ru/post/1394986/


All Articles