Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RuntimeException: Font asset not found optimale_bold.ttf

Here is the error line:

Typeface typeface = Typeface.createFromAsset(getAssets(), "optimale_bold.tff");

Here is the error log cat:

Caused by: java.lang.RuntimeException: Font asset not found optimale_bold.tff
at android.graphics.Typeface.createFromAsset(Typeface.java:192)
at com.leontheprofessional.test.whorepresentsyou.activity.MainActivity.onCreate(MainActivity.java:100)
at android.app.Activity.performCreate(Activity.java:6020)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2284)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2393) 
at android.app.ActivityThread.access$800(ActivityThread.java:151) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1309) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:135) 
at android.app.ActivityThread.main(ActivityThread.java:5351) 
at java.lang.reflect.Method.invoke(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:372) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:908) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:703) 

Here is the structure of assets folder:
in main directory:

|-assets
|--optimale_bold.ttf
|-java
|-res
AndrodMainifest.xml

in Android view of AndroidStudio:

|-app
|--manifest
|--java
|--res
|--assets
|---optimale_bold.tff

I carefully checked the app.iml file, such a line is included:

<option name="ASSETS_FOLDER_RELATIVE_PATH" value="/src/main/assets" />

What might be wrong?

PS: I checked this post, and tried every solution. But none works. This is not a duplicate post. Please help solve the problem.

To those who might need:

compileSdkVersion 23
buildToolsVersion "23.0.1"

defaultConfig {
    applicationId "blahblah"
    minSdkVersion 11
    targetSdkVersion 23
    versionCode 1
    versionName "1.0"
}
like image 985
Leon Avatar asked Nov 17 '25 04:11

Leon


2 Answers

I think you have some misspelling error. Your font extension should be .ttf, and not .tff

like image 54
Kashmir Avatar answered Nov 18 '25 19:11

Kashmir


It is a good practice to add fonts folder inside assets and then use this line,

Typeface face1= Typeface.createFromAsset(getAssets(), "fonts/optimale_bold.tff");

Also to make sure that the assets folder sits in the same level as java and res.

like image 44
Arup Saha Avatar answered Nov 18 '25 18:11

Arup Saha



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!