2

I am trying to use the Calibri font on a button in one of my Android applications, and after searching around for a bit i found out how to make your own Typeface. But when i try to set the typeface on the button it doesn't give me an error, but the application won't launch. Does anyone know how to fix that?

final Button bt4 = (Button) findViewById(R.id.bt4);
final Typeface font = Typeface.createFromAsset(getAssets(),"CALIBRI.ttf");
bt4.setTypeface(font);

this is pretty much all the code i have used to this point.

and the log cat information

08-29 13:31:20.593: E/global(1143): Deprecated Thread methods are not supported.
08-29 13:31:20.593: E/global(1143): java.lang.UnsupportedOperationException
08-29 13:31:20.593: E/global(1143):     at java.lang.VMThread.stop(VMThread.java:85)
08-29 13:31:20.593: E/global(1143):     at java.lang.Thread.stop(Thread.java:1280)
08-29 13:31:20.593: E/global(1143):     at java.lang.Thread.stop(Thread.java:1247)
08-29 13:31:20.593: E/global(1143):     at com.github.TheCad.nijmegen1.SplashScreen$1.run(SplashScreen.java:33)
08-29 13:31:21.553: D/AndroidRuntime(1143): Shutting down VM
08-29 13:31:21.553: W/dalvikvm(1143): threadid=1: thread exiting with uncaught exception (group=0x40015560)
08-29 13:31:21.583: E/AndroidRuntime(1143): FATAL EXCEPTION: main
08-29 13:31:21.583: E/AndroidRuntime(1143): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.github.TheCad.nijmegen1/com.github.TheCad.nijmegen1.MainActivity}: java.lang.RuntimeException: native typeface cannot be made
08-29 13:31:21.583: E/AndroidRuntime(1143):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
08-29 13:31:21.583: E/AndroidRuntime(1143):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
08-29 13:31:21.583: E/AndroidRuntime(1143):     at android.app.ActivityThread.access$1500(ActivityThread.java:117)
08-29 13:31:21.583: E/AndroidRuntime(1143):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
08-29 13:31:21.583: E/AndroidRuntime(1143):     at android.os.Handler.dispatchMessage(Handler.java:99)
08-29 13:31:21.583: E/AndroidRuntime(1143):     at android.os.Looper.loop(Looper.java:123)
08-29 13:31:21.583: E/AndroidRuntime(1143):     at android.app.ActivityThread.main(ActivityThread.java:3683)
08-29 13:31:21.583: E/AndroidRuntime(1143):     at java.lang.reflect.Method.invokeNative(Native Method)
08-29 13:31:21.583: E/AndroidRuntime(1143):     at java.lang.reflect.Method.invoke(Method.java:507)
08-29 13:31:21.583: E/AndroidRuntime(1143):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
08-29 13:31:21.583: E/AndroidRuntime(1143):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
08-29 13:31:21.583: E/AndroidRuntime(1143):     at dalvik.system.NativeStart.main(Native Method)
08-29 13:31:21.583: E/AndroidRuntime(1143): Caused by: java.lang.RuntimeException: native typeface cannot be made
08-29 13:31:21.583: E/AndroidRuntime(1143):     at android.graphics.Typeface.<init>(Typeface.java:147)
08-29 13:31:21.583: E/AndroidRuntime(1143):     at android.graphics.Typeface.createFromAsset(Typeface.java:121)
08-29 13:31:21.583: E/AndroidRuntime(1143):     at com.github.TheCad.nijmegen1.MainActivity.onCreate(MainActivity.java:25)
08-29 13:31:21.583: E/AndroidRuntime(1143):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
08-29 13:31:21.583: E/AndroidRuntime(1143):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
08-29 13:31:21.583: E/AndroidRuntime(1143):     ... 11 more
13
  • Without looking into your code, nobody can suggest or help you out. Aug 29, 2012 at 13:38
  • and relevant logcat information.
    – Ben Weiss
    Aug 29, 2012 at 13:39
  • did you update your activity in AndroidManifest.xml ? Aug 29, 2012 at 13:46
  • What exactly do you mean by updating?
    – TheCad
    Aug 29, 2012 at 13:47
  • 2
    Might want to keep in mind the Calibri font included with Windows isn't licensed for redistribution. Aug 29, 2012 at 14:04

2 Answers 2

1

You have create TypeFace to do at RunTime.

Example:

Button btn=(Button)findViewById(R.id.BUTTON_ID);
Typeface face=Typeface.createFromAsset(getAssets(), "fonts/FONT_NAME.TTF");
btn.setTypeface(face);

Update: You have error at 25th line of mainactivity. Post that line.

1
  • 1
    That is the line final Typeface font = Typeface.createFromAsset(getAssets(),"CALIBRI.ttf");
    – TheCad
    Aug 29, 2012 at 13:57
0

create a folder named "font" in the assets folder and store your font "calibri.ttf" in that folder, also try saving your font name in small letters and use this code,

Button btn=(Button)findViewById(R.id.BUTTON_ID);
Typeface face= = Typeface.createFromAsset(getAssets(), "font/calibri.ttf");
btn.setTypeface(face);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.