Android Runtime Exception font asset not found

后端 未结 13 639
执念已碎
执念已碎 2021-01-04 01:11

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 som

相关标签:
13条回答
  • 2021-01-04 01:31

    I had the problem that .woff fonts are not accepted on Android 7+. So i switched to .ttf fonts.

    0 讨论(0)
  • 2021-01-04 01:34

    If you're using Instant Run with Android Gradle plugin version 2.2.0-alphaX, it is a known bug.

    A workaround is to turn of Instant Run until the issue is resolved.

    You can track it here: https://code.google.com/p/android/issues/detail?id=212849&can=1&q=subcomponent%3DTools-Studio%20-has%3Aproject%20attachments%3D0&colspec=ID%20Status%20Priority%20Owner%20Summary%20Stars%20Reporter%20Opened&start=7700

    0 讨论(0)
  • 2021-01-04 01:34

    Typeface typeface = Typeface.createFromAsset(this.getAssets(),"font/terminal.ttf");

    ((TextView) findViewById(R.id.weatherHeadingTV)).setTypeface(typeface);

    0 讨论(0)
  • 2021-01-04 01:34

    I have tried another font file that worked fine So I conclude that earlier font file was corrupt. Thanks @Miduhun MP , @Gowtham Raj and @jagan reddy

    0 讨论(0)
  • 2021-01-04 01:40

    I had the same problem and managed to fix it. Originally I thought the font files were corrupt but they weren't. Then I thought Android Studio didn't like .ttf files, because they were the only ones not working. Turns out it's nothing wrong with the fonts.

    FIX: Just click Build > Clean project. Fixed it straight away for me.

    0 讨论(0)
  • 2021-01-04 01:40

    For me, the font file itself was corrupted. I tried another one to make it work.

    0 讨论(0)
提交回复
热议问题