0

I am facing the above error on an app that used to work fine as of few months ago, with no changes since then. The only change is updated Android studio/gradle

The 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)
    ....

The XML in question is

<?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>

And 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);
    }

}

The difference between this and the myriad other questions on this error appears to be that the line refers to a custom widget. If i were to remove this widget, the crash doesnt occur here anymore, but occurs at the next usage of this widget.. and (I suspect) so on..

Any idea into this? We have tried to clean and rebuild project as well..

Karthik T
  • 31,456
  • 5
  • 68
  • 87

1 Answers1

1

Try to remove app:font="@string/lusitana line. and try How to change fontFamily of TextView in Android to change font style.

Community
  • 1
  • 1
NehaK
  • 2,639
  • 1
  • 15
  • 31
  • This might be the answer. Removing that line doesnt cause the crash at this XML. Can you provide any reasoning into why this helps? – Karthik T Jun 18 '15 at 10:01
  • This is because TextView has not property of app:font is undefined in android. You can use android:fontFamily="@string/lusitana" instead of app:font="@string/lusitana" – NehaK Jun 18 '15 at 10:08
  • You are right, I talked to my colleague and seem this was defined on our end, and it was working, but it stopped. We removed the code using this property and now it works well. – Karthik T Jun 19 '15 at 07:23