ERROR: android.view.InflateException: Binary XML file line # 0: Error inflating class TextView

1

Using LayoutInflater with this XML gives the following error:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <TextView
            android:textSize="?android:attr/textAppearanceSmall"
            android:textStyle="bold"
            android:id="@+id/title_view"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Title View"/>

        <TextView
            android:textSize="?android:attr/textAppearanceSmall"
            android:textAllCaps="false"
            android:id="@+id/author_view"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Author View"/>

    </LinearLayout>

</LinearLayout>
        E/AndroidRuntime: FATAL EXCEPTION: main
                                                                               Process: com.example.android.bookslist, PID: 22347
                                                                               android.view.InflateException: Binary XML file line #0: Binary XML file line #0: Error inflating class TextView
                                                                               Caused by: android.view.InflateException: Binary XML file line #0: Error inflating class TextView
                                                                               Caused by: java.lang.UnsupportedOperationException: Can't convert value at index 2 to dimension: type=0x1
                                                                                   at android.content.res.TypedArray.getDimensionPixelSize(TypedArray.java:723)
                                                                                   at android.widget.TextView.<init>(TextView.java:1134)
                                                                                   at android.widget.TextView.<init>(TextView.java:751)
                                                                                   at android.support.v7.widget.AppCompatTextView.<init>(AppCompatTextView.java:75)
                                                                                   at android.support.v7.widget.AppCompatTextView.<init>(AppCompatTextView.java:71)
                                                                                   at android.support.v7.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:103)
                                                                                   at android.support.v7.app.AppCompatDelegateImplV9.createView(AppCompatDelegateImplV9.java:1024)
                                                                                   at android.support.v7.app.AppCompatDelegateImplV9.onCreateView(AppCompatDelegateImplV9.java:1081)
                                                                                   at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:769)
                                                                                   at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:727)
                                                                                   at android.view.LayoutInflater.rInflate(LayoutInflater.java:858)
                                                                                   at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821)
                                                                                   at android.view.LayoutInflater.rInflate(LayoutInflater.java:861)
                                                                                   at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821)
                                                                                   at android.view.LayoutInflater.inflate(LayoutInflater.java:518)
                                                                                   at android.view.LayoutInflater.inflate(LayoutInflater.java:426)
                                                                                   at com.example.android.bookslist.BookAdapter.getView(BookAdapter.java:29)
                                                                                   at android.widget.AbsListView.obtainView(AbsListView.java:2522)
                                                                                   at android.widget.ListView.makeAndAddView(ListView.java:2017)
                                                                                   at android.widget.ListView.fillDown(ListView.java:721)
                                                                                   at android.widget.ListView.fillFromTop(ListView.java:782)
                                                                                   at android.widget.ListView.layoutChildren(ListView.java:1749)
                                                                                   at android.widget.AbsListView.onLayout(AbsListView.java:2280)
                                                                                   at android.view.View.layout(View.java:17841)
                                                                                   at android.view.ViewGroup.layout(ViewGroup.java:5754)
                                                                                   at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1982)
                                                                                   at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1826)
                                                                                   at android.widget.LinearLayout.onLayout(LinearLayout.java:1735)
                                                                                   at android.view.View.layout(View.java:17841)
                                                                                   at android.view.ViewGroup.layout(ViewGroup.java:5754)
                                                                                   at android.widget.FrameLayout.layoutChildren(FrameLayout.java:383)
                                                                                   at android.widget.FrameLayout.onLayout(FrameLayout.java:321)
                                                                                   at android.view.View.layout(View.java:17841)
                                                                                   at android.view.ViewGroup.layout(ViewGroup.java:5754)
                                                                                   at android.support.v7.widget.ActionBarOverlayLayout.onLayout(ActionBarOverlayLayout.java:443)
                                                                                   at android.view.View.layout(View.java:17841)
                                                                                   at android.view.ViewGroup.layout(ViewGroup.java:5754)
                                                                                   at android.widget.FrameLayout.layoutChildren(FrameLayout.java:383)
                                                                                   at android.widget.FrameLayout.onLayout(FrameLayout.java:321)
                                                                                   at android.view.View.layout(View.java:17841)
                                                                                   at android.view.ViewGroup.layout(ViewGroup.java:5754)
                                                                                   at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1982)
                                                                                   at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1826)
                                                                                   at android.widget.LinearLayout.onLayout(LinearLayout.java:1735)
                                                                                   at android.view.View.layout(View.java:17841)
                                                                                   at android.view.ViewGroup.layout(ViewGroup.java:5754)
                                                                                   at android.widget.FrameLayout.layoutChildren(FrameLayout.java:383)
                                                                                   at android.widget.FrameLayout.onLayout(FrameLayout.java:321)
                                                                                   at com.android.internal.policy.DecorView.onLayout(DecorView.java:751)
                                                                                   at android.view.View.layout(View.java:17841)
                                                                                   at android.view.ViewGroup.layout(ViewGroup.java:5754)
                                                                                   at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2712)
                                                                                   at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2385)
                                                                                   at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1463)
                                                                                   at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6965)
02-17 09:44:00.352 22347-22347/com.example.android.bookslist E/AndroidRuntime:     at android.view.Choreographer$CallbackRecord.run(Choreographer.java:907)
                                                                                   at android.view.Choreographer.doCallbacks(Choreographer.java:709)
                                                                                   at android.view.Choreographer.doFrame(Choreographer.java:644)
                                                                                   at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:893)
                                                                                   at android.os.Handler.handleCallback(Handler.java:836)
                                                                                   at android.os.Handler.dispatchMessage(Handler.java:103)
                                                                                   at android.os.Looper.loop(Looper.java:203)
                                                                                   at android.app.ActivityThread.main(ActivityThread.java:6314)
                                                                                   at java.lang.reflect.Method.invoke(Native Method)
                                                                                   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1063)
                                                                                   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:924)
    
asked by anonymous 17.02.2018 / 13:01

1 answer

3

The problem is caused by the attributes of TextView of XML.

Instead of being:

android:textSize="?android:attr/textAppearanceSmall"

Should be:

android:textAppearance="?android:attr/textAppearanceSmall"

Because textSize only accepts parameters in dp , or more correctly, in sp . Unfortunately, by doing the wrong thing, Android Studio does not show any error messages.

I found the answer based on this question in StackOverflow En.

    
17.02.2018 / 13:01