Android Studio Native typeface cannot be made error


Error Trace:
05-01 12:31:26.249  16555-16555/? E/AndroidRuntimeοΉ• FATAL EXCEPTION: main
    java.lang.RuntimeException: Unable to start activity ComponentInfo 
             {com.code2care.someapp/com.code2care.someapp.MainActivity}: 
           
            java.lang.RuntimeException: native typeface cannot be made
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
            at android.app.ActivityThread.access$1500(ActivityThread.java:117)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:130)
            at android.app.ActivityThread.main(ActivityThread.java:3687)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:507)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:878)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:636)
            at dalvik.system.NativeStart.main(Native Method)
     Caused by: java.lang.RuntimeException: native typeface cannot be made
            at android.graphics.Typeface.(Typeface.java:147)
            at android.graphics.Typeface.createFromAsset(Typeface.java:121)
            at com.code2care.someapp.MainActivity.onCreate(MainActivity.java:149)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
            at android.app.ActivityThread.access$1500(ActivityThread.java:117)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:130)
            at android.app.ActivityThread.main(ActivityThread.java:3687)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:507)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:878)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:636)
            at dalvik.system.NativeStart.main(Native Method)
Android Studio Native typeface cannot be made is the error message I received while I was trying to migrate one of my projects from Eclipse to Android Studio. Solution :

The problem was that I had created the assets/fonts folder manually and placed the .ttf font file in it,

Steps resolve the issue
  1. Delete the assets folder if you had created manually.
  2. Now move to package view.
  3. Right Click on app and select New -> Folder -> Assets Folder
  4. Now move back to Projects view and you must now see assets folder under yourPackageName->app->src->main->assets
  5. Just add the fonts folder and the ttf file inside it
  6. Now things should work fine.

Also make sure that the way you create the Typeface object in Java file is also correct,

Typeface tf = Typeface.createFromAsset(getAssets(), "fonts/roboto.ttf");



















Copyright Β© Code2care 2024 | Privacy Policy | About Us | Contact Us | Sitemap