I've read every SO post regarding use of fonts in Android and I still can't get mine to work. I'm getting the following exception:
java.lang.RuntimeException: native typeface cannot be made
Here's my code (this class and static method is taken from here):
public class SafeTypefaces {
private static final Hashtable<String, Typeface> cache = new Hashtable<String, Typeface>();
public static Typeface get(Context c) {
final String assetPath = "fonts/robotobold.ttf";
synchronized (cache) {
if (!cache.containsKey(assetPath)) {
try {
AssetManager assetManager = c.getAssets();
Typeface t = Typeface.createFromAsset(assetManager, assetPath); //Throws exception on this line!
cache.put(assetPath, t);
} catch (Exception e) {
L.p("Could not get typeface '" + assetPath + "' because " + e.getMessage());
return null;
}
}
return cache.get(assetPath);
}
}
}
The font is in the assets/fonts
folder:
(this is still Eclipse. I know, I know).
Things I've tried:
- I've tried moving the font to the root of the
assets
folder and updating theassetPath
. - I checked folder and file permissions.
- I tried using the application context instead of the activity context I'm getting.
- I tried using different font files (one send via email, another downloaded from the Internet).