51

I'm trying to use a font I found on the internet, but the problem is that I get an FC with "native typeface cannot be made".

Here is the code in the getView of my ListVIew:

        holder.tv_SuraName   =(TextView)convertView.findViewById(R.id.Start_Name);
        holder.tv_SuraName.setTypeface(Typeface.createFromAsset(mContext.getAssets(), "suralist_font.ttf"));

Can anyone tell me why can I use the custom rom? You can get it HERE .. the file is .ttf

Omar
  • 7,835
  • 14
  • 62
  • 108

16 Answers16

48

My problem was incorrect placement of the assets folder.

When using Android Studio the assets folder should be inside of the source sets e.g.

src/main/assets/

Found in this answer

Community
  • 1
  • 1
roelvogel
  • 734
  • 6
  • 10
37

The font file is either corrupt or unsupported for some reason. You can drop it on the SD card and load it from file, to make sure it's not a problem with your assets.

Nikolay Elenkov
  • 52,576
  • 10
  • 84
  • 84
  • 1
    I just tried from File and now the font works! But this means I have a problem with my assets folder, will this affect anything else? Is there a way to fix this problem? – Omar Sep 23 '11 at 16:53
  • Shouldn't affect other stuff. You can try rebuilding your apk, but not sure what exactly is the problem. Maybe it fails to decompress the file? Try using the newest Android SDK. – Nikolay Elenkov Sep 24 '11 at 11:50
  • how to drop it out on sdcard ? when a random person is downloading my app from the play store? – Cyph3rCod3r Apr 16 '13 at 15:48
  • 1
    As a side note: Android studio users need to create an assests folder in src/main because of gradle build rather than the build/assets folder. http://stackoverflow.com/questions/18302603/where-to-place-assets-folder-in-android-studio/18302624#18302624 – cjayem13 Oct 12 '14 at 02:07
29

There are basically 4 things that can cause this:

  1. You use the wrong extension
  2. You have to place the fonts in the assets folder and not inside assets/fonts/
  3. You misspelled the fonts
  4. The fonts need to be lowercase (in my case the solution was to rename MyFont.ttf to myfont.ttf, strange)
Dr.jacky
  • 3,341
  • 6
  • 53
  • 91
erdomester
  • 11,789
  • 32
  • 132
  • 234
21

Double check the extension isn't in caps, ie. suralist_font.TTF

Fonts often come seem to come that way and it might be overlooked.

tlrmcknz
  • 629
  • 6
  • 3
9

I had this same problem, I created mine in assets>fonts>whatever.ttf and was getting the same error. I added the fonts extension (fonts/whatever.ttf) and it fixed the problem in every case.

 holder.tv_SuraName   =(TextView)convertView.findViewById(R.id.Start_Name);
 holder.tv_SuraName.setTypeface(Typeface.createFromAsset(mContext.getAssets(),    "fonts/suralist_font.ttf"));
a54studio
  • 965
  • 11
  • 11
2

Rather old thread, but I want to add one more reason this can happen: You have to set the content view before calling typeface. See example below

Does not work:

@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        TextView title = (TextView)findViewById(R.id.tvTitle);
        Typeface font = Typeface.createFromAsset(this.getAssets(), "fonts/whatever.ttf");
        title.setTypeface(font);

        setContentView(R.layout.main);
    }

Does work!

@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main); // <-- call before typeface

        TextView title = (TextView)findViewById(R.id.tvTitle);
        Typeface font = Typeface.createFromAsset(this.getAssets(), "fonts/whatever.ttf");
        title.setTypeface(font);
    }
Alina B.
  • 1,256
  • 8
  • 18
2

I am using android studio, in my case problem was with the path of assets folder, in Eclipse path for assets folder is res/assets/ but in Android Studio its src/main/assets/ So, i just move my font file to this path and finally problem solved.

Rahul Sharma
  • 5,949
  • 5
  • 36
  • 46
2

Either your font file is corrupt else you making some mistake in spelling while calling your file name. I had same issue, it was because file name specified in asset folder was

roboto_black.ttf

and while declaring in java file, i have been spelling it as:

roboto_blak.ttf

If your .ttf files are in asset folder,then use:

Typeface type_bold = Typeface.createFromAsset(getAssets(), "roboto_black.ttf");

Else if it is in fonts folder, then use:

type_bold = Typeface.createFromAsset(getAssets(), "fonts/roboto_black.ttf");

Hope it helps!

0

Hope this will help

Typeface.createFromAsset leaks asset stream: http://code.google.com/p/android/issues/detail?id=9904

Pawan Maheshwari
  • 15,088
  • 1
  • 48
  • 50
0

I had the same problem with COMIC.TTF from comic sans ms of Windows. Since the original file I placed in assets/fonts folder was in uppercase as spelt above, I had to type it exactly in uppercase. Typeface.createFromAsset(getAssets(), "fonts/COMIC.TTF");

it turns out the problem was caused by the lower case: Typeface.createFromAsset(getAssets(), "fonts/comic.ttf");

Olumide Oyetoke
  • 329
  • 4
  • 17
0

Please note that this is due to either a corrupt file or you have placed the file in the wrong folder.

According to Android documentation here

main/assets/ This is empty. You can use it to store raw asset files. Files that you save here are compiled into an .apk file as-is, and the original filename is preserved. You can navigate this directory in the same way as a typical file system using URIs and read files as a stream of bytes using the AssetManager. For example, this is a good location for textures and game data.

Therefore your folder structure should be yourmodule/main/assets (e.g. a***pp/main/assets*** )

d4c0d312
  • 748
  • 8
  • 24
0

What worked for me was first changing my font name to only lower case and underscore: from Amatic-Sc.ttf to amatic_sc.ttf.

Then in the set.TypeFace method change assets/fonts/amatic_sc.ttf to just fonts/amatic_sc.ttf.

0

I've been debugging forever on this error in Android Studio. Clean and rebuilding the project after adding the fonts to the assets directory fixed the issue for me.

RuudJ
  • 53
  • 8
0

Just did a build --> clean and it started rendering .

Anukool
  • 5,301
  • 8
  • 29
  • 41
0

I had same issue which happened on Android 4.0.3-4.0.4 (100% reproducible on emulator IceCreamSandwich mips 4.0.3).

The problem was that TTF fonts, that I had, were not correct, despite almost all Android versions were able to load those TTF font. So I used https://cloudconvert.com/woff-to-ttf (since I had woff files as well) to make new TTF fonts, which solved my problem.

negersiu
  • 552
  • 3
  • 20
0

As CommonsWare states in this answer

I would guess that there is a problem with the font itself. That error will be triggered when native code in the OS attempts to load the typeface.

Anyway try this one:

holder.tv_SuraName = (TextView)convertView.findViewById(R.id.Start_Name);
Typeface Font = Typeface.createFromAsset(this.getAssets(),"suralist_font.ttf");
holder.tv_SuraName.setTypeface(Font);
Community
  • 1
  • 1
Mr.James
  • 376
  • 2
  • 8
  • 25