android.view.InflateException:二进制XML文件行#13:错误输出类<unknown>

时间:2015-06-18 09:45:37

标签: android xml android-layout

我在几个月前曾经工作正常的应用程序面临上述错误,此后没有任何变化。唯一的变化是更新Android studio / gradle

stacktrace

06-18 21:37:52.817  27995-27995/com.XYZ.carnival.debug E/AndroidRuntime﹕ FATAL EXCEPTION: main
    Process: com.XYZ.carnival.debug, PID: 27995
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.XYZ.carnival.debug/com.XYZ.carnival.MainActivity}: android.view.InflateException: Binary XML file line #13: Error inflating class <unknown>
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2693)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2758)
            at android.app.ActivityThread.access$900(ActivityThread.java:177)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1448)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:145)
            at android.app.ActivityThread.main(ActivityThread.java:5942)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1400)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1195)
     Caused by: android.view.InflateException: Binary XML file line #13: Error inflating class <unknown>
            at android.view.LayoutInflater.createView(LayoutInflater.java:640)
            at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:750)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:813)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:511)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:415)
            at com.XYZ.carnival.drawer.Account.AccountViewController.initAdapter(AccountViewController.java:69)
            at com.XYZ.carnival.drawer.Account.AccountViewController.initViews(AccountViewController.java:53)
            at com.XYZ.carnival.drawer.Account.AccountViewController.<init>(AccountViewController.java:43)
    ....

有问题的XML是

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="#93928c"
    android:orientation="vertical"
    android:paddingBottom="5dp"
    android:paddingLeft="22dp"
    android:paddingRight="20dp"
    android:paddingTop="5sp">

    <com.XYZ.carnival.widgets.CrTextView
        android:id="@+id/tv_account_name"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="bottom"
        android:minHeight="38dp"
        android:text="MichaelCARN_2839ef1524 Jon Siegal"
        android:textColor="@color/white"
        android:textSize="22sp"
        android:textStyle="bold"
        app:font="@string/lusitana" />
</LinearLayout>

和CrTextView

package com.XYZ.carnival.widgets;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.TextView;

import com.XYZ.carnival.utils.TypefaceManager;

public class CrTextView extends TextView {

    public static final String TAG = CrTextView.class.getSimpleName();

    public CrTextView(Context ctx) {
        this(ctx, null);
    }

    public CrTextView(Context ctx, AttributeSet attrs) {
        this(ctx, attrs, android.R.attr.textViewStyle);
    }

    public CrTextView(Context ctx, AttributeSet attrs, int defStyle) {
        super(ctx, attrs, defStyle);
        init(ctx, attrs, defStyle);
    }

    private void init(Context ctx, AttributeSet attrs, int defStyle) {
        if (isInEditMode()) return;
        TypefaceManager.applyFont(this, attrs, defStyle);
    }

}

此错误和有关此错误的无数其他问题之间的差异似乎是该行指的是自定义窗口小部件。如果我要删除这个小部件,崩溃不再发生在这里,但发生在下一次使用这个小部件..并且(我怀疑)等等..

对此有何看法?我们也试图清理和重建项目..

1 个答案:

答案 0 :(得分:1)

尝试删除app:font="@string/lusitana行。并尝试How to change fontFamily of TextView in Android更改字体样式。