RuntimeException的:原生字体不可言 [英] RuntimeException: native typeface cannot be made

查看:393
本文介绍了RuntimeException的:原生字体不可言的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用自定义字体在列表视图的元素。所以在我的ListViewAdapter构造我有:

I'm trying to use a custom font on elements of a listview. So in my ListViewAdapter constructor I have:

private Context context;
private List<Project> projects;
private Typeface tf;
public ListViewAdapter(Context context, int resource, List<Project> projects) {
    super(context, resource, projects);
    this.context = context;
    this.projects = projects;
    tf = getTypefaceForListItems();
}

public Typeface getTypefaceForListItems()
{
    return Typeface.createFromAsset(context.getAssets(), "fonts/OpenSans-Regular.ttf");
}

在getView方法,我将此字样以一个TextView。问题是,我得到一个运行时异常:原始字体不能言,我不明白什么似乎是问题

In getView method I apply this typeface to a textview. The problem is that I get a Runtime exception: native typeface cannot be made and I don't understand what seems to be the problem.

下面的堆栈跟踪:

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.maxcode.clientcheck.ProjectListAdapter.getTypefaceForListItems(ProjectListAdapter.java:41)
            at com.maxcode.clientcheck.ProjectListAdapter.<init>(ProjectListAdapter.java:25)
            at com.maxcode.clientcheck.ProjectListActivity$GetProjectsAsyncTask.onPostExecute(ProjectListActivity.java:154)
            at com.maxcode.clientcheck.ProjectListActivity$GetProjectsAsyncTask.onPostExecute(ProjectListActivity.java:91)
            at android.os.AsyncTask.finish(AsyncTask.java:631)
            at android.os.AsyncTask.access$600(AsyncTask.java:177)
            at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:644)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:137)
            at android.app.ActivityThread.main(ActivityThread.java:4745)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:511)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
            at dalvik.system.NativeStart.main(Native Method)

此外,我想提一提,我所有的字体都是在src / main /租入资产价值/ fonts文件夹中。

Also I wanted to mention that all my fonts are in src/main/assests/fonts folder.

推荐答案

就是忽视(搭载Android Studio用户)的一个问题是,资产/文件夹不在同一水平的src /。这里面的钢骨混凝土/主/

One problem that's overlooked (by Android Studio users) is that the "assets/" folder is NOT on the same level as "src/". It is INSIDE "src/main/"

由于我没有看到这个早些时候,我花了两个小时,昨晚,一个小时今天上午只是想改变字体在我的抽屉式导航。

Because I didn't see this earlier, I spent two hours last night, and an hour this morning just trying to change the font in my navigation drawer.

我相信这是一样的道理,为什么pixlUI和书法库没有为我工作。

I believe this is the same reason why pixlUI and calligraphy libraries did not work for me.

这篇关于RuntimeException的:原生字体不可言的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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