Android "font asset not found" error

12,171

Solution 1

Assets folder should be under root directory of main folder which inner folder of src.

For Reference Please find attached images of folder structure.

enter image description here

enter image description here

Solution 2

I am guessing that my file structure is wrong because the "assets" folder does not show up in "Android" mode and only shows up in "Project Mode"

According to your screenshots, you do not have an "assets" folder. You have a res/assets.fonts/ folder. It has the wrong name (assets.fonts, not assets) and is in the wrong location (a child of res/).

Step #1: In your project tree, right-click over main.

Step #2: Choose New > Directory from the context menu that appears when you right-clicked.

Step #3: In the resulting dialog, type assets, then click OK. You will now have an assets/ directory under main.

Step #4: In your project tree, right-click over your newly-created assets directory.

Step #5: Choose New > Directory from the context menu that appears when you right-clicked.

Step #6: In the resulting dialog, type 'fonts', then click OK. You will now have an assets/fonts/ directory under main.

Step #7: Drag your font file from its current location to move it into assets/fonts/.

Step #8: Delete the res/assets.fonts/ directory, which is now empty.

Solution 3

I am guessing that my file structure is wrong because the "assets" folder does not show up in "Android" mode and only shows up in "Project Mode".

Your assets is empty you can't see it in "Android mode". Change mode to "Project" and add your font to assets folder.

Right location of assets folder:

root-module
|--.idea
|--app
|----build
|----src
|------main
|--------assets
|----------norwester.otf
|--------java
|----------source code here
|--------res
|------AndroidManifest.xml
|----build.gradle

To create assets folder Right click on app->New->Folder->Assets Folder like below image.

Create assets folder

Share:
12,171
Foobar
Author by

Foobar

Just a random person who like to code and make apps.

Updated on June 07, 2022

Comments

  • Foobar
    Foobar about 2 years

    I am developing for Android version 22.

    I am getting the runtime exception "Font asset not found"

    Here is the code:

    Typeface customFont =    Typeface.createFromAsset(getAssets(), "fonts/norwester.otf");
    

    And here is my file structure:

    First part of file structure

    Second part of file stucture

    3rd part of file structure

    I am guessing that my file structure is wrong because the "assets" folder does not show up in "Android" mode and only shows up in "Project Mode".

    What is the problem?