Nama
Nama

Reputation: 308

Binary XML file line #26: Error inflating class android.widget.TextView

I am using Android Studio, when i use textview in my layout application is closing showing error:

android.view.InflateException: Binary XML file line #26: Error inflating class android.widget.TextView
            at android.view.LayoutInflater.createView(LayoutInflater.java:633)
            at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:55)
            at android.view.LayoutInflater.onCreateView(LayoutInflater.java:682)
            at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:741)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:809)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
            at com.SubFragment.onCreateView(SubFragment.java:20)
            at android.support.v4.app.Fragment.performCreateView(Fragment.java:1786)
            at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:947)
            at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1126)
            at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:739)
            at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1489)
            at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:486)
            at android.support.v4.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:141)
            at android.support.v4.view.ViewPager.populate(ViewPager.java:1073)
            at android.support.v4.view.ViewPager.populate(ViewPager.java:919)
            at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1441)
            at android.view.View.measure(View.java:17430)
            at android.widget.LinearLayout.measureVertical(LinearLayout.java:875)
            at android.widget.LinearLayout.onMeasure(LinearLayout.java:613)
            at android.view.View.measure(View.java:17430)
            at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5463)
            at android.widget.FrameLayout.onMeasure(FrameLayout.java:430)
            at android.view.View.measure(View.java:17430)
            at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5463)
            at android.widget.FrameLayout.onMeasure(FrameLayout.java:430)
            at android.view.View.measure(View.java:17430)
            at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5463)
            at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1436)
            at android.widget.LinearLayout.measureVertical(LinearLayout.java:722)
            at android.widget.LinearLayout.onMeasure(LinearLayout.java:613)
            at android.view.View.measure(View.java:17430)
            at android.support.v4.widget.DrawerLayout.onMeasure(DrawerLayout.java:851)
            at android.view.View.measure(View.java:17430)
            at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5463)
            at android.widget.FrameLayout.onMeasure(FrameLayout.java:430)
            at android.view.View.measure(View.java:17430)
            at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5463)
            at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1436)
            at android.widget.LinearLayout.measureVertical(LinearLayout.java:722)
            at android.widget.LinearLayout.onMeasure(LinearLayout.java:613)
            at android.view.View.measure(View.java:17430)
            at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5463)
            at android.widget.FrameLayout.onMeasure(FrameLayout.java:430)
            at android.view.View.measure(View.java:17430)
            at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5463)
            at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1436)
            at android.widget.LinearLayout.measureVertical(LinearLayout.java:722)
            at android.widget.LinearLayout.onMeasure(LinearLayout.java:613)
            at android.view.View.measure(View.java:17430)
            at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5463)
            at android.widget.FrameLayout.onMeasure(FrameLayout.java:430)
            at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2560)
            at android.view.View.measure(View.java:17430)

and here in my Fragment class

public class SubFragment extends Fragment{


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.fragment_homescreen, container, false);// getting error here


        return rootView;
    }


}

XML code:

<LinearLayout
        android:layout_margin="10dp"
        android:layout_width="match_parent"
        android:orientation="vertical"
        android:gravity="center_vertical|center_horizontal"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:background="@drawable/offers">


        <ImageView
            android:id="@+id/imageButtonOffers"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_centerVertical="true"
            android:src="@drawable/offers_icon" />

        <TextView
            android:id="@+id/textViewOffers"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/imageButtonOffers"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="5dp"
            android:gravity="center_horizontal"
            android:text="Offer"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:textColor="@color/white"
            android:textSize="15sp" />


    </LinearLayout>

this code is working fine with eclipse. only problem when i try to work in Studio

Upvotes: 13

Views: 37926

Answers (8)

Willey Hute
Willey Hute

Reputation: 1078

Check your theme parent. If mismatch happens between theme parent and style parent you get the attribute missing or failed to resolve error. In my case I was using a theme of parent :

Theme.AppCompat.DayNight.NoActionBar

But in my style I used parent as :

TextAppearance.AppCompat.Widget.PopupMenu.Small

Since they are different it causes failed to resolve symbol error. Hope this might help..

Upvotes: 0

Himanshu Gupta
Himanshu Gupta

Reputation: 71

You have to create another .xml file in the res-> font folder of your project. After that call the font file in the .xml file.

<font
    android:font="@font/rubikbold"/>

Here, I have a robik bold font file in my project.

Upvotes: 0

Ashwin Balani
Ashwin Balani

Reputation: 771

It seems old versions of Android do not support tags like,

android:background="@drawable/rounded_corner"
android:textSize="?android:textAppearanceMedium"

In that case, remove it from the XML file, and try to load the attributes from the Java or Kotlin code (preferably inside a try...catch or an if...else clause)

Hope it helps

Upvotes: 0

trustidkid
trustidkid

Reputation: 557

I encountered similar error but I found out the attribute textAppearance was not properly written.

initially android:textSize="?android:textAppearanceMedium" instead of android:textAppearance="?android:textAppearanceMedium"

you can read more about TextView here https://developer.android.com/reference/android/widget/TextView

Upvotes: -1

E_K
E_K

Reputation: 2249

I was Faced with the same problem. Make sure you Do not have tools:targetApi="lollipop" in any of your Layouts.Instead, have two Layouts one under layout add the other under layout-v21 folder.

Upvotes: 1

Omkar
Omkar

Reputation: 3100

I also encountered this error.

I solved it by simply recreating new .xml file containing TextView. In my case, the error was the xml version(v21\abc.xml). code run well in android version 6(marshmallow) rather than it throws error while run in android version 4.4(kitkat).

Upvotes: 1

M S Gadag
M S Gadag

Reputation: 2057

android:background="@drawable/offers"

i hope offers is image and its larger than the screen so replace by some color code n try

Like this

android:background="#ff0000"

hope it works..

check this too

android.view.InflateException: Binary XML file line #12: Error inflating class <unknown>

edit:

remove this line

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

Upvotes: 14

Juanjo Vega
Juanjo Vega

Reputation: 1440

I cleaned up your xml and added the namespace:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_margin="10dp"
    android:layout_weight="1"
    android:background="@drawable/offers"
    android:gravity="center_vertical|center_horizontal"
    android:orientation="vertical" >

<ImageView
    android:id="@+id/imageButtonOffers"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/offers_icon" />

<TextView
    android:id="@+id/textViewOffers"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="5dp"
    android:gravity="center_horizontal"
    android:text="Offer"
    android:textAppearance="?android:attr/textAppearanceMedium"
    android:textColor="@color/white"
    android:textSize="15sp" />

</LinearLayout>

As you are using a LinearLayout, parameters like "android:layout_below" or "android:layout_centerHorizontal" are not invalid.

Upvotes: 1

Related Questions