Pablo De Luca
Pablo De Luca

Reputation: 823

Java.Lang.RuntimeException: Font asset not found

As the title suggest, the font file seems that can't be found. I quote the error:

Unhandled Exception:

Java.Lang.RuntimeException: Font asset not found fontawesome-webfont.ttf"

The code is:

public class MainActivity : Activity
{
    protected override void OnCreate(Bundle bundle)
    {
        base.OnCreate(bundle);

        SetContentView(Resource.Layout.Main);

        AssetManager assets = this.Assets;
        Typeface font = Typeface.CreateFromAsset(assets, "fontawesome-webfont.ttf");

        // Set our view from the "main" layout resource
        Button button = (Button)FindViewById(Resource.Id.btnIniciarSesion);
        button.SetTypeface(font, TypefaceStyle.Normal);

        // Get our button from the layout resource,
        // and attach an event to it
    }
}

The font file is in the assets folder, as you can see in the following image:

font file inside assets folder

What can I try?

Upvotes: 1

Views: 4730

Answers (4)

Younes
Younes

Reputation: 46

try this instruction it work for me

Typeface oswaldFont = Typeface.CreateFromAsset(Assets, "Oswald.ttf");

Upvotes: 0

Evgeniy
Evgeniy

Reputation: 75

you should set in "fontawesome-webfont.ttf" file properties -> build Action and choose AndroidAsset

Upvotes: 1

Pablo De Luca
Pablo De Luca

Reputation: 823

I deleted and created again the solution and the problem has 'magically' disappeared.

Upvotes: 0

Manoj Perumarath
Manoj Perumarath

Reputation: 10194

Try this,

Typeface font = Typeface.createFromAsset(getContext().getAssets(),  "fontawesome-webfont.ttf");

Upvotes: 1

Related Questions