空指针异常,而进口在android系统字体 [英] Null pointer exception while importing a font in android

查看:460
本文介绍了空指针异常,而进口在android系统字体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图导入字体。看了一些网上的教程和使用的指令。到目前为止,我已经导入的字体到资产的文件夹。这是code,我使用申报我的字体类型。

I am trying to import a font. Looked for some tutorials online and used the instructions. So far I've imported the font onto the assets folder. This is the code that I am using to declare my font type.

Typeface localTypeface1 = Typeface.createFromAsset(getAssets(), "arial.ttf");

我不断收到空指针异常,当我把它。

I keep getting null pointer exception when I call it.

TextView txtTab = new TextView(this);
txtTab.setTypeface(localTypeface1);

这可能是什么问题呢?
这是logcat的确切的错误。

What could be the problem ? This is the exact error in logcat.

11-17 13:10:41.024: E/AndroidRuntime(2262): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{se.copernicus.activity/se.copernicus.activity.Secondactivity}: java.lang.NullPointerException
11-17 13:10:41.024: E/AndroidRuntime(2262): at android.content.ContextWrapper.getAssets(ContextWrapper.java:74)

这是第74行

Typeface localTypeface1 = Typeface.createFromAsset(getAssets(), "arial.ttf");

推荐答案

我所看到的是,Android的不能读一些TTF文件。 (也许该文件已损坏?)

What I have seen is that, Android cannot read some ttf files. (maybe the file is corrupted?)

我是不是能够使用TTF文件在我的应用程序,但在我的手机另一个应用程序能够读取相同的ttf文件。 (我用同样的code如上,试图清洗,替换它的文件夹差异似乎没什么工作)

I was not able to use a ttf file in my app but another app in my phone was able to read the same ttf file. (I used the same code as above, tried cleaning, replacing it diff folders nothing seemed to work)

结束了使用不同的字体文件完全。 (没有遇到任何问题与此文件具有相同code!)

Ended up using a different font file altogether. (Had no issues with this file with the same code!)

这篇关于空指针异常,而进口在android系统字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆