Android Runtime Exception font asset not found

Muzammil Husnain picture Muzammil Husnain · Nov 24, 2015 · Viewed 32.9k times · Source

Here is my code and screenshot I'm trying to set custom font typeface but Runtime exception occurs font asset not found while font file is in asset folder. Am I missing something ?

Typeface font = Typeface.createFromAsset(getAssets(), "font/terminal.ttf");
((TextView) findViewById(R.id.weatherHeadingTV)).setTypeface(font);

enter image description here screenshot of android studio project

Answer

smarteist picture smarteist · May 1, 2019

Use this method :

final Typeface typeface = ResourcesCompat.getFont(context, R.font.X);

ResourcesCompat class is a compatible way to retrieve your resources.