
但在运行我的应用程序后,它在所有文件中显示以下错误 –
com.pack.demo.MyFontedTextVIEw无法实例化MyFontedTextVIEw是类文件的位置,并且com.pack.demo.MyFontedEditText无法实例化.
在我的所有布局中,我得到运行时异常 –
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)在Typeface Font = Typeface.createFromAsset(context.getAssets(),“calibri.otf”)中显示错误.在下面的类文件中.
这是我的Fonted edittext的代码 –
public class MyFontedEditText extends EditText { public MyFontedEditText(Context context) { super(context); // Todo auto-generated constructor stub 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(),AttributeSet attrs,int defStyle) { super(context,attrs,defStyle); Typeface Font = Typeface.createFromAsset(context.getAssets(),"calibri.otf"); this.setTypeface(Font); } } 同样,我的Fonted textvIEw代码 –
public class MyFontedTextVIEw extends TextVIEw { public MyFontedTextVIEw(Context context) { super(context); // Todo auto-generated constructor stub 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,int defStyle) { super(context,defStyle); Typeface Font = Typeface.createFromAsset(context.getAssets(),Typeface.BolD); }}解决方法 试试这种方式,希望这可以帮助您解决问题. public class MyFontedTextVIEw extends TextVIEw { private Context context; public MyFontedTextVIEw(Context context,defStyle); init(context); } public MyFontedTextVIEw(Context context,attrs); init(context); } public MyFontedTextVIEw(Context context) { super(context); this.context=context; init(context); } private voID init(Context mContext) { try { Typeface tf = Typeface.createFromAsset(mContext.getAssets(),"calibri.otf"); setTypeface(tf,Typeface.BolD); } catch (Throwable e) { } }} 总结 以上是内存溢出为你收集整理的android – 在我的应用程序中设置自定义文本样式时出错全部内容,希望文章能够帮你解决android – 在我的应用程序中设置自定义文本样式时出错所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)