Forum Xamarin.Android

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, and also the font Build Action is set to AndroidAsset

What can I try?
Thanks a lot.

Tagged:

Best Answer

Answers

  • jaymarvelsjaymarvels GBMember ✭✭

    In the Assets folder create folder named - fonts, with a lower case 'f', now you need to create the typeface:
    var tf = Android.Graphics.Typeface.CreateFromAsset (Context.Assets, "fonts/fontawesome-webfont.ttf"); then after that set the typeface to the button: button.SetTypeface(tf, Android.Graphics.TypefaceStyle.Normal);

  • pablo.delucapablo.deluca USMember
    edited November 2016

    @jaymarvels said:
    In the Assets folder create folder named - fonts, with a lower case 'f', now you need to create the typeface:
    var tf = Android.Graphics.Typeface.CreateFromAsset (Context.Assets, "fonts/fontawesome-webfont.ttf"); then after that set the typeface to the button: button.SetTypeface(tf, Android.Graphics.TypefaceStyle.Normal);

    Thanks for your reply, I' ve just tried it and the issue persist.

    EDIT: I attached an image just in case

    1.png 105.9K
  • LeonardHarrisLeonardHarris USMember ✭✭

    Clean and then rebuild the droid project should fix the issue too.

  • EliranEliran USMember ✭✭✭

    @LeonardHarris Didn't solve this exact problem :'(
    Does anyone have an other solution for this problem?

  • louisconlouiscon JPMember

    Also having this issue... @Eliran did you find a solution?

  • VipinRaturiVipinRaturi USMember

    For me, it was stupid reason. The font files were excluded in solution for some reason. I included it and worked fine.

Sign In or Register to comment.