Font asset not found helvetica.ttf on lollipop –

Development issue/problem:

For some reason I get this mistake on lollipops, and since lollipops are so new, I can’t understand why, and I have no idea how to do it. Thank you in advance for the logcat error:

java.lang.RuntimeException : Can ComponentInfo{com.bent.MissionaryTracker.MainActivity}:java.lang.RuntimeException : Active with font not found helvetica.ttf
on android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298)
on android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
to android.app.activityThread.access$800 (ActivityThread.java:144)
to android.app.activityThread$H.handleMessage (ActivityThread.java:1278)
to android.os.Handler.dispatchMessage (Handler.java:102)
to android.os.Looper.loop(Looper.java:135)
to android.app.ActivityThread.main(ActivityThread.java:5221)
to java.lang.reflect.Method.invoke(Native Method)
to java.lang.reflect.Method.invoke(Method.java:372)
to com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
to com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
Reason: java.lang.RuntimeException : Font asset not found helvetica.ttf
at android.graphics.Typeface.createFromAsset (Typeface.java:190)
at com.bent.MissionaryTracker.MainActivity.onCreate (MainActivity.java:57)
at android.app.Activity.performCreate(Activity.java:5933)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
…. Another 10

EDIT: HERE’S THE CODE THAT CAUSED THE ERROR…

title = (TextView) findViewById(R.id.title) ;

Font = Typeface.createFromAsset(getAssets(), helvetica.ttf) ;
title.setTypeface(font) ;

I have helvetica.ttf in the asset folder of the project files.

EDIT:
This application works on all devices up to and including version 5.0. For some reason, version 5.0 does not recognize the file in the My Assets folder.

I tried to place a screenshot in my assets folder, but I don’t have enough credit to post photos.

How can I solve this problem?

Solution 1:

If you work with Android Studio, make sure your assets are in the root folder and not in the
folder.

Solution 2:

It is now preferable to use this approach for custom fonts.

Saving fonts in red/font

To the :

Type the font = ResourcesCompat.getFont(context, R.font.myfont) ;

Solution 3:

I, too, had this problem before I realized that I hadn’t preceded the .otf file with fonts/.

Font type = Typeface.createFromAsset(getAssets(),fonts/TTTMastersDEMOBlack.ttf) ;

Solution 4:

It worked for me. In my case it didn’t work because I created an assets map in res instead of in main.

See also  Android vibrate is deprecated. How to use VibrationEffect in Android>= API 26? –

Give here a description of the image

Solution No 5:

If the folder change does not work, the Android team may have already fixed the problem, but didn’t have time to do it during version 5.0. It’s all explained here:

https://code.google.com/p/android-developer-preview/issues/detail?id=608&thanks=608&ts=1404735239

The solution (at least for me) is to correct font files with TTX, as mentioned in a related problem.

Running TTX can be a bit cumbersome if you have no experience with Pythons, so I finally downloaded Adobe’s AFDKO, including TTX. You need to run ttx yourfontfile.ttf which will convert your file to .ttx and then run ttx yourfontfile.ttx again to get a new .ttf that works with version 5.0.

Solution No 6:

Clear project, it worked for me on Android 6.0.

Solution No 7:

Put the Assets folder in the root folder.
After that:

Typeface=Typeface.createFromAsset(getAssets(),OpenSans-Light.ttf) ;
textView.setTypeface(font) ;

Solution No 8:

I’ve encountered this problem before. I removed x.ttf, then I undid the removal and tried to boot without locking. So I just erased it, downloaded the font again and added it to the font file, and it worked fine.

Solution No 9:

Okay, guys,

I had the same problem. First of all, I made my font loading logic shockproof:

/**
* Init method. This method must be called for any other call in this class.
*/
public static void init() {
fontPlain = createFont( helveteticab.ttf , Typeface.NORMAL ) ;
fontBold = createFont( helveteticab.ttf , Typeface.BOLD ) ;
}

/**
* Load the font from the Asset Font folder.
*/
public static Typeface createFont (String font, int style) {
Typeface;
try {
AssetManager assets = Kit.getAppContext().getAssets();
typeface = Typeface.createFromAsset( assets, fonts + File.separator + font );
}
catch (RuntimeException e) {
// createFromAsset() launches a RuntimeException if it fails.
Log.e ( Constants.TAG, Cannot create font: + font, e );
font = Typeface.defaultFromStyle( style );
}
inverted font;
}

See also  Remote not Working | How to pair your Roku Remote

I also downloaded another font from this project in git:

https://github.com/dimanchec3/Tutoriapps-Android/blob/master/assets/Helvetica.ttf

I noticed that my old font was 56 KB and the new one 84 KB. I think I had an older version of the police.

Make sure you have the correct license before using this policy.

Good luck!

Related Tags:

font asset not found xamarin,font asset not found fonts calibri ttf,xamarin forms custom font,xamarin forms font awesome,xamarin css font size,java lang runtimeexception font asset not found fonts null,r font not found android,java lang runtimeexception font asset not found font roboto_medium ttf,android studio resource font not found,get typeface from font folder android,how to get fonts from assets in android