0

Update:

I created an asset folder and inside of it is a century.ttf file. First I got a wrong encoding problem but after I followed these steps after File was loaded in the wrong encoding 'UTF-8' while pasting new font to Assets Folder in Android Studio the error message disappeared. Then I wrote into my MainActivity:

FOURTH UPDATE:

Typeface typeface = Typeface.createFromAsset(getAssets(),"century.ttf");
Text.setTypeface(typrface);

But then my app suddenly stops.

FOURTH UPDATE:

09-08 20:17:54.742 1266-1301/? E/cutils: Failed to mkdir(/data/system/users/0): No such file or directory
09-08 20:17:54.742 1266-1301/? E/vold: Failed to prepare /data/system/users/0: No such file or directory
09-08 20:17:54.743 1266-1301/? E/vold: Failed to prepare user 0 storage
09-08 20:17:54.822 1266-1314/? E/Cryptfs: Bad magic for real block device /dev/block/vdd
09-08 20:17:54.742 1266-1301/? E/cutils: Failed to mkdir(/data/system/users/0): No such file or directory
09-08 20:17:54.742 1266-1301/? E/vold: Failed to prepare /data/system/users/0: No such file or directory
09-08 20:17:54.743 1266-1301/? E/vold: Failed to prepare user 0 storage
09-08 20:17:54.822 1266-1314/? E/Cryptfs: Bad magic for real block device /dev/block/vdd
09-08 20:17:56.997 1310-1310/? E/libEGL: load_driver(/system/lib/egl/libGLES_emulation.so): dlopen failed: library "/system/lib/egl/libGLES_emulation.so" not found
09-08 20:17:57.012 1266-1301/? E/vold: Failed to chmod /data/system_ce/0: No such file or directory
09-08 20:17:57.012 1266-1301/? E/vold: Failed to chmod /data/misc_ce/0: No such file or directory
09-08 20:17:57.012 1266-1301/? E/vold: Failed to chmod /data/media/0: No such file or directory
09-08 20:17:57.048 1310-1310/? E/SurfaceFlinger: hwcomposer module not found
09-08 20:17:57.851 1310-1326/? E/SurfaceFlinger: ro.sf.lcd_density must be defined as a build property
09-08 20:17:57.853 1340-1345/? E/libEGL: load_driver(/system/lib/egl/libGLES_emulation.so): dlopen failed: library "/system/lib/egl/libGLES_emulation.so" not found
09-08 20:18:05.693 1266-1301/? E/vold: Failed to chmod /data/system_ce/0: No such file or directory
09-08 20:18:05.693 1266-1301/? E/vold: Failed to chmod /data/misc_ce/0: No such file or directory
09-08 20:18:05.693 1266-1301/? E/vold: Failed to chmod /data/media/0: No such file or directory
09-08 20:18:05.928 1405-1405/? E/cutils: Failed to read /data/.layout_version: No such file or directory

                                         [ 09-08 20:18:05.928  1405: 1405 D/         ]
                                         Assuming that device has multi-user storage layout; upgrade no longer supported

                                         [ 09-08 20:18:05.928  1405: 1405 D/         ]
                                         Upgrading to /data/misc/user directories
09-08 20:18:05.968 1416-1416/? E/perfprofd: unable to open configuration file /data/data/com.google.android.gms/files/perfprofd.conf
09-08 20:18:06.123 1403-1403/? E/EmulatedCamera_Factory: 2 cameras are being emulated. 0 of them are fake cameras.
09-08 20:18:06.123 1403-1403/? E/EmulatedCamera_HotplugThread: createFileIfNotExists: Could not create file '/data/misc/media/emulator.camera.hotplug.0', error: 'Permission denied' (13)
09-08 20:18:06.123 1403-1403/? E/EmulatedCamera_HotplugThread: createFileIfNotExists: Could not create file '/data/misc/media/emulator.camera.hotplug.1', error: 'Permission denied' (13)
09-08 20:18:06.123 1403-1403/? E/CameraService: setUpVendorTags: Vendor tag operations not fully defined. Ignoring definitions.
09-08 20:18:06.204 1402-1402/? E/RadioService: couldn't load radio module radio.primary (No such file or directory)
09-08 20:18:06.204 1402-1402/? E/SoundTriggerHwService: couldn't load sound trigger module sound_trigger.primary (No such file or directory)
09-08 20:18:07.021 1534-1534/? E/ipv6proxy: Failed to forward Neighbor Solicitation for fe80::5c01:45ff:fe1b:e65c from radio0-peer to eth0: Cannot assign requested address
09-08 20:18:07.039 1544-1544/? E/hostapd: Configuration file: /system/etc/simulated_hostapd.conf
09-08 20:18:07.308 1401-1401/? E/memtrack: Couldn't load memtrack module (No such file or directory)
09-08 20:18:07.308 1401-1401/? E/android.os.Debug: failed to load memtrack module: -2
09-08 20:18:07.695 1401-1401/? E/Typeface: Error mapping font file /system/fonts/DroidSansFallback.ttf
09-08 20:18:08.021 1534-1534/? E/ipv6proxy: Failed to forward Router Advertisement from eth0 to wlan1: Network is unreachable
09-08 20:18:08.021 1534-1534/? E/ipv6proxy: Failed to forward Router Advertisement from eth0 to radio0-peer: Cannot assign requested address
09-08 20:18:08.231 1411-1411/? E/Netd: cannot find interface dummy0
09-08 20:18:08.398 1401-1401/? E/libEGL: load_driver(/system/lib/egl/libGLES_emulation.so): dlopen failed: library "/system/lib/egl/libGLES_emulation.so" not found
09-08 20:18:08.423 1401-1401/? E/Hyphenator: error loading hyphenation /system/usr/hyphen-data/hyph-as.hyb
                                                                                            java.io.FileNotFoundException: /system/usr/hyphen-data/hyph-nb.hyb: open failed: ENOENT (No such file or directory)
                                                 at libcore.io.IoBridge.open(IoBridge.java:455)
                                                 at java.io.RandomAccessFile.<init>(RandomAccessFile.java:247)
                                                 at android.text.Hyphenator.loadHyphenator(Hyphenator.java:118)
                                                 at android.text.Hyphenator.init(Hyphenator.java:224)
                                                 at com.android.internal.os.ZygoteInit.preloadTextResources(ZygoteInit.java:252)
                                                 at com.android.internal.os.ZygoteInit.preload(ZygoteInit.java:206)
                                                 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:743)
                                              Caused by: android.system.ErrnoException: open failed: ENOENT (No such file or directory)
                                                 at libcore.io.Posix.open(Native Method)
                                                 at libcore.io.BlockGuardOs.open(BlockGuardOs.java:187)
                                                 at libcore.io.IoBridge.open(IoBridge.java:441)
                                                 at java.io.RandomAccessFile.<init>(RandomAccessFile.java:247) 
                                                 at android.text.Hyphenator.loadHyphenator(Hyphenator.java:118) 
                                                 at android.text.Hyphenator.init(Hyphenator.java:224) 
                                                 at com.android.internal.os.ZygoteInit.preloadTextResources(ZygoteInit.java:252) 
                                                 at com.android.internal.os.ZygoteInit.preload(ZygoteInit.java:206) 
                                                 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:743) 
09-08 20:18:08.430 1401-1401/? E/Hyphenator: error loading hyphenation /system/usr/hyphen-data/hyph-nn.hyb
                                             java.io.FileNotFoundException: /system/usr/hyphen-data/hyph-nn.hyb: open failed: ENOENT (No such file or directory)
                                                 at libcore.io.IoBridge.open(IoBridge.java:455)
                                                 at java.io.RandomAccessFile.<init>(RandomAccessFile.java:247)
                                                 at android.text.Hyphenator.loadHyphenator(Hyphenator.java:118)
                                                 at android.text.Hyphenator.init(Hyphenator.java:224)
                                                 at com.android.internal.os.ZygoteInit.preloadTextResources(ZygoteInit.java:252)
                                                 at com.android.internal.os.ZygoteInit.preload(ZygoteInit.java:206)
                                                 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:743)
                                              Caused by: android.system.ErrnoException: open failed: ENOENT (No such file or directory)
                                                 at libcore.io.Posix.open(Native Method)
                                                 at libcore.io.BlockGuardOs.open(BlockGuardOs.java:187)
                                                 at libcore.io.IoBridge.open(IoBridge.java:441)
                                                 at java.io.RandomAccessFile.<init>(RandomAccessFile.java:247) 
                                                 at android.text.Hyphenator.loadHyphenator(Hyphenator.java:118) 
                                                 at android.text.Hyphenator.init(Hyphenator.java:224) 
                                                 at com.android.internal.os.ZygoteInit.preloadTextResources(ZygoteInit.java:252) 
                                                 at com.android.internal.os.ZygoteInit.preload(ZygoteInit.java:206) 
                                                 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:743) 
09-08 20:18:08.430 1401-1401/? E/Hyphenator: error loading hyphenation /system/usr/hyphen-data/hyph-or.hyb
                                             java.io.FileNotFoundException: /system/usr/hyphen-data/hyph-or.hyb: open failed: ENOENT (No such file or directory)
                                                 at libcore.io.IoBridge.open(IoBridge.java:455)
                                                 at java.io.RandomAccessFile.<init>(RandomAccessFile.java:247)
                                                 at android.text.Hyphenator.loadHyphenator(Hyphenator.java:118)
                                                 at android.text.Hyphenator.init(Hyphenator.java:224)
                                                 at com.android.internal.os.ZygoteInit.preloadTextResources(ZygoteInit.java:252)
                                                 at com.android.internal.os.ZygoteInit.preload(ZygoteInit.java:206)
                                                 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:743)
                                              Caused by: android.system.ErrnoException: open failed: ENOENT (No such file or directory)
                                                 at libcore.io.Posix.open(Native Method)
                                                 at libcore.io.BlockGuardOs.open(BlockGuardOs.java:187)
                                                 at libcore.io.IoBridge.open(IoBridge.java:441)
                                                 at java.io.RandomAccessFile.<init>(RandomAccessFile.java:247) 
                                                 at android.text.Hyphenator.loadHyphenator(Hyphenator.java:118) 
                                                 at android.text.Hyphenator.init(Hyphenator.java:224) 
                                                 at com.android.internal.os.ZygoteInit.preloadTextResources(ZygoteInit.java:252) 
                                                 at com.android.internal.os.ZygoteInit.preload(ZygoteInit.java:206) 
                                                 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:743) 
09-08 20:18:08.430 1401-1401/? E/Hyphenator: error loading hyphenation /system/usr/hyphen-data/hyph-pa.hyb
                                             java.io.FileNotFoundException: /system/usr/hyphen-data/hyph-pa.hyb: open failed: ENOENT (No such file or directory)
                                                 at libcore.io.IoBridge.open(IoBridge.java:455)
                                                 at java.io.RandomAccessFile.<init>(RandomAccessFile.java:247)
                                                 at android.text.Hyphenator.loadHyphenator(Hyphenator.java:118)
                                                 at android.text.Hyphenator.init(Hyphenator.java:224)
                                                 at com.android.internal.os.ZygoteInit.preloadTextResources(ZygoteInit.java:252)
                                                 at com.android.internal.os.ZygoteInit.preload(ZygoteInit.java:206)
                                                 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:743)
                                              Caused by: android.system.ErrnoException: open failed: ENOENT (No such file or directory)
                                                 at libcore.io.Posix.open(Native Method)
                                                 at libcore.io.BlockGuardOs.open(BlockGuardOs.java:187)
                                                 at libcore.io.IoBridge.open(IoBridge.java:441)
                                                 at java.io.RandomAccessFile.<init>(RandomAccessFile.java:247) 
                                                 at android.text.Hyphenator.loadHyphenator(Hyphenator.java:118) 
                                                 at android.text.Hyphenator.init(Hyphenator.java:224) 
                                                 at com.android.internal.os.ZygoteInit.preloadTextResources(ZygoteInit.java:252) 
                                                 at com.android.internal.os.ZygoteInit.preload(ZygoteInit.java:206) 
                                                 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:743) 
09-08 20:18:08.431 1401-1401/? E/Hyphenator: error loading hyphenation /system/usr/hyphen-data/hyph-pt.hyb
                                                                               Process: com.example.fdai3744.t_online20, PID: 3050
                                                                               java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.fdai3744.t_online20/com.example.fdai3744.t_online20.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setTypeface(android.graphics.Typeface)' on a null object reference
                                                                                   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2665)
                                                                                   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)
                                                                                   at android.app.ActivityThread.-wrap12(ActivityThread.java)
                                                                                   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477)
                                                                                   at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                                   at android.os.Looper.loop(Looper.java:154)
                                                                                   at android.app.ActivityThread.main(ActivityThread.java:6119)
                                                                                   at java.lang.reflect.Method.invoke(Native Method)
                                                                                   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
                                                                                   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
                                                                                Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setTypeface(android.graphics.Typeface)' on a null object reference
                                                                                   at com.example.fdai3744.t_online20.MainActivity.onCreate(MainActivity.java:25)
                                                                                   at android.app.Activity.performCreate(Activity.java:6679)
                                                                                   at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
                                                                                   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2618)
                                                                                   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726) 
                                                                                   at android.app.ActivityThread.-wrap12(ActivityThread.java) 
                                                                                   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477) 
                                                                                   at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                                   at android.os.Looper.loop(Looper.java:154) 
                                                                                   at android.app.ActivityThread.main(ActivityThread.java:6119) 
                                                                                   at java.lang.reflect.Method.invoke(Native Method) 
                                                                                   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886) 

FOURTH UPDATE:

enter image description here

Ramón Wilhelm
  • 967
  • 2
  • 18
  • 39

4 Answers4

2

Follow the instructions in the link below and go to the manifest file and add android:name="the-below-implementation" under application xml tag

https://github.com/chrisjenx/Calligraphy

sam
  • 1,800
  • 1
  • 25
  • 47
1

Considering you use ttf fonts in asset folder, generate typeface like this.

Typeface typeface = Typeface.createFromAsset(getAssets(),"YourFontName.ttf"); 
Text.setTypeface(typrface);
Aalap Patel
  • 2,058
  • 2
  • 17
  • 31
1

Your code is requesting font/century (see: Caused by: java.lang.RuntimeException: Font asset not found font/century). The actual asset is font/century.tff (according to your comment), or possibly font/century.ttf (which would be the more likely file extension for TrueType fonts).

The font path you provide needs to match the actual path in assets/, including file extensions.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • I added the .tff extension but I still get errors. Now I updated the LogCat so you can see the actual error. In my assets folder is only the century.tff. – Ramón Wilhelm Sep 08 '17 at 18:57
  • 1
    @RamónWilhelm: There is no `century.tff` file in `assets/`, according to the error. You keep writing a file extension of `.tff`. Are you **absolutely certain** that the file really has a file extension with one `t` and two `f`'s, instead of two `t`'s and one `f`? The standard file extension for TrueType fonts is `.ttf`, not `.tff` as you keep writing. – CommonsWare Sep 08 '17 at 19:00
  • I changed ".tff" to ".ttf" but nothing happens. I changed the LogCat again. – Ramón Wilhelm Sep 08 '17 at 19:05
  • @RamónWilhelm: The error message shows that your code still refers to `.tff`, not `.ttf`. The screenshot shows the same. – CommonsWare Sep 08 '17 at 19:19
  • I updated the LogCat and the image. This are my last modifications. – Ramón Wilhelm Sep 08 '17 at 20:25
  • 1
    @RamónWilhelm: I do not recognize `Error mapping font file /system/fonts/DroidSansFallback.ttf`, and I am not quite certain why that message would appear. Regardless, it is not a stack trace, and so I have no idea if it is even related to your app or this code. Your screenshot now seems consistent, with respect to the asset location and what you are asking for with `Typeface`. What are your current symptoms? FWIW, [here is a sample app](https://github.com/commonsguy/cw-omnibus/tree/master/Fonts/FontSampler) where I use custom fonts. – CommonsWare Sep 08 '17 at 20:29
  • I've updated LogCat again. I will inspect the sample App. Thank you and thank you for your help. You tried your best. But I don't know why my android studio don't allow me to work with fonts normally. – Ramón Wilhelm Sep 08 '17 at 21:01
  • 1
    @RamónWilhelm: `java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setTypeface(android.graphics.Typeface)' on a null object reference`. `tv001` is `null`. – CommonsWare Sep 08 '17 at 21:48
  • OMG! I am so clumsy! :o Thank you so much! – Ramón Wilhelm Sep 08 '17 at 23:08
1

Try putting the ttf file into a "fonts" folder inside the "Assets" folder and then change the source path "fonts/century.ttf". My guess is that the file isn't being recognized as a font file.

This is how I have it set-up in one of my projects:

enter image description here