Click here to Skip to main content
15,891,529 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi I am developing an android widget which displays some sentences,
the problem is that I cannot pass typeface to the widget.
and when I use mytextview.settypeface(...); the program comes out with force close.
any help would be appreciated,
tnx in advance
Posted

1 solution

Without seeing your code and without knowing what exception is being thrown what follows is all guesswork. I take it you are using something like the following?

Java
String fontFamily = "Arial";
Typeface tf = Typeface.Create(fontFamily, Typeface.DEFAULT);
myTextView.setTypeface(tf);


  • Have you a null reference to the myTextView?
  • Is the font family you want to use actually present?
  • What does Typeface.Create() return if the font family isn't available?


Assuming you are using Eclipse; suggest that you run the offending code in the emulator and either single step from a break point and/or wrap the failing code in a try/catch block and log the exception details which will then be available for inspection in logcat.

See setTypeface[^]
and Typeface[^]
 
Share this answer
 
Comments
Behno0o0oD 27-Apr-14 6:49am    
tnx, yes,
textview is null because I am setting typeface to the textview in OnCreate(), and the problem is that , widget has not been run when OnCreate() method is being executed.

In my broadcast receiver class I can make instance from MainActivity class, but it does not set typeface to the textview.

Tnx

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900