我有一个针对特定字体的自定义文本视图类。
我的班:‘
public LobsterTextView(Context context, AttributeSet attrs) {
super(context, attrs);
Typeface face=Typeface.createFromAsset(context.getAssets(), "lobster1_4.otf");
this.setTypeface(face);
}
public LobsterTextView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
Typeface face=Typeface.createFromAsset(context.getAssets(), "lobster1_4.otf");
this.setTypeface(face);
}}
我的布局:
<x.y.z.LobsterTextView
android:id="@+id/tv_mobile_name"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:textSize="@dimen/font_large3"
android:layout_marginTop="@dimen/fab_margin"
android:layout_marginLeft="@dimen/fab_margin"
android:textColor="@color/colorAccent_3"
android:text="Register with Pika" />和错误:‘呈现问题--无法实例化以下类:- io.pika.pike_store.utils.LobsterTextView (Open,Show,清除缓存)提示:使用自定义视图中的android.graphics.Typeface.createAssetUid(Typeface.java:219) ()跳过代码或显示示例数据时,在IDE异常详细信息中显示,java.lang.NullPointerException在io.pika.pike_store.utils.LobsterTextView.(LobsterTextView.java:22),io.pika.pike_store.utils.LobsterTextView.(LobsterTextView.java:22),at at java.lang.reflect.Constructor.newInstance(Constructor.java:423),at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:727)在android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:858))在android.view.LayoutInflater.rInflate(LayoutInflater.java:834)中,重水化,重熔,在android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821),重熔,在android.view.LayoutInflater_Delegate.parseInclude(LayoutInflater_Delegate.java:197),变价,在android.view.LayoutInflater.parseInclude(LayoutInflater.java:902),改性,改性,再加工,再加工,android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:70),android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:70),android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:70),android.view。LayoutInflater.rInflate(LayoutInflater.java:834)在android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821)上进行辅助处理,在android.view.LayoutInflater.inflate(LayoutInflater.java:518)上进行分级,在android.view.LayoutInflater.inflate(LayoutInflater.java:397)上复制堆栈,剪贴板,LobsterTextView自定义视图是最近编辑的,而不是上一次构建:构建项目。
我的代码一旦运行fine.but,当我进入布局文件时,这个错误总是出现在前台。
我怎样才能解决这个问题?
发布于 2016-09-30 07:54:03
公共类PahariTextView扩展TextView {
public PahariTextView(Context context) {
super(context);
applyCustomFont(context);
}
public PahariTextView(Context context, AttributeSet attrs) {
super(context, attrs);
applyCustomFont(context);
}
public PahariTextView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
applyCustomFont(context);
}
private void applyCustomFont(Context context) {
Typeface customFont = FontCache.getTypeface("fonts/quicksand_light.otf", context);
setTypeface(customFont);
}}
https://stackoverflow.com/questions/39786332
复制相似问题