I use a special font for TextView and EditText in an Android application. I made a separate class for edittext and textview fonts. I use the Calibri font for my text.
But after starting my application, the following error is displayed in all files: -
com.pack.demo.MyFontedTextView failed to create an instance where MyFontedTextView is a class file and com.pack.demo.MyFontedEditText failed to create an instance.
In all my layouts, I get a runtime exception as
java.lang.RuntimeException: native typeface cannot be made
at android.graphics.Typeface.<init>(Typeface.java:175)
at android.graphics.Typeface.createFromAsset(Typeface.java:149)
at com.pack.demo.MyFontedTextView.<init>(MyFontedTextView.java:22)
com.pack.demo.MyFontedTextView. (MyFontedTextView.java:22) shows a font error Typeface = Typeface.createFromAsset (context.getAssets (), "calibri.otf"); in the file below the class.
Here is the code for my edittext font -
public class MyFontedEditText extends EditText {
public MyFontedEditText(Context context) {
super(context);
Typeface font = Typeface.createFromAsset(context.getAssets(),
"calibri.otf");
this.setTypeface(font);
}
public MyFontedEditText(Context context, AttributeSet attrs) {
super(context, attrs);
Typeface font = Typeface.createFromAsset(context.getAssets(),
"calibri.otf");
this.setTypeface(font);
}
public MyFontedEditText(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
Typeface font = Typeface.createFromAsset(context.getAssets(),
"calibri.otf");
this.setTypeface(font);
}
}
, -
public class MyFontedTextView extends TextView {
public MyFontedTextView(Context context) {
super(context);
Typeface font = Typeface.createFromAsset(context.getAssets(),
"calibri.otf");
this.setTypeface(font);
this.setTypeface(null, Typeface.BOLD);
}
public MyFontedTextView(Context context, AttributeSet attrs) {
super(context, attrs);
Typeface font = Typeface.createFromAsset(context.getAssets(),
"calibri.otf");
Log.d("1", "abc");
this.setTypeface(font);
this.setTypeface(null, Typeface.BOLD);
}
public MyFontedTextView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
Typeface font = Typeface.createFromAsset(context.getAssets(),
"calibri.otf");
this.setTypeface(font);
this.setTypeface(null, Typeface.BOLD);
}
}