Android java.lang.RuntimeException: 无法制作原生字体

Android java.lang.RuntimeException: native typeface cannot be made

我在尝试为按钮设置自定义字体时遇到以下异常:java.lang.RuntimeException: native typeface cannot be made 我已经看过类似的问题,但是 none 他们的解决方案有效。

我的字体在src/main里面,文件结构好像没问题。

文件结构如下:

这是代码:

private void generateButtonListener(final Button btn,final String inputText) {

    btn.setTypeface(Typeface.createFromAsset(getAssets(), "rb.ttf"));

    btn.setOnClickListener(new android.view.View.OnClickListener() {
        public void onClick(View view1) {
            getCurrentInputConnection().commitText(inputText,1);
        }

    });


}

不确定这是否重要,但我正在制作一个自定义键盘应用程序,所以我在 onCreateInputView 方法中的按钮上设置此侦听器。像这样:

   @Override
public View onCreateInputView() {

    LayoutInflater lInflate = getLayoutInflater();
    Resources res = getResources();
    LinearLayout inputView = (LinearLayout) lInflate.inflate(R.layout.copypasta, null);
    Button tab_navySeal = (Button) inputView.findViewById(R.id.tab_navySeal);
  Button nSeal_1 = (Button) btnset_navyseal.findViewById(R.id.nSeal_1);
        generateButtonListener(nSeal_1, res.getString(R.string.NStxt));

等...

我似乎遵守了所有字体规则,有什么问题吗?

您是将字体用作库还是

btn.setTypeface(Typeface.createFromAsset(getAssets(), "rb.ttf"));

rb.ttf是错误的路径吗?尝试fonts/rb.ttf