13

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

7
  • can u pls post xml and all ? Commented Feb 9, 2015 at 8:16
  • double check your xml file, where you declare your textview, this means you have made a spelling mistake somewhere. Probably forgot a character or something. Commented Feb 9, 2015 at 8:19
  • @user1140237 added xml Commented Feb 9, 2015 at 8:19
  • @SboneloMbhamali, I tested this, the same code working in eclipse, i have postred my xml code for reference Commented Feb 9, 2015 at 8:23
  • 3
    You are missing the namespace declaration. Add xmlns:android="http://schemas.android.com/apk/res/android" to the LinearLayout. Commented Feb 9, 2015 at 8:34

8 Answers 8

14
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"
Sign up to request clarification or add additional context in comments.

4 Comments

remove this android:textAppearance="?android:attr/textAppearanceMedium" n try
this answer helped for me
I solved the strange problem, when change the line android:textSize, I put the value directly and not from dimens xml file. Like this: android:textSize="35sp"
@ M S Gadag, What we have to do if " parent="TextAppearance.Widget.AppCompat.Toolbar.Title"> " this line is in styles.xml
1

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.

2 Comments

first i tried with the Relative layout, so i have used layout_below params.. and this is a child of my main xml, so as of my knowledge, there is no need of adding namespace again for child
The, you should paste your entire xml layout. It's confusing otherwise.
1

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

Comments

1

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.

1 Comment

When I had this problem, all I did to fix it was remove the android:drawableLeft statement. It turns out that assigning an image to an AutoCompleteTextView on pre-Lollipop devices causes the problem. On my Lollipop phone, it works fine.
0

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

Comments

0

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.

Comments

0

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

Comments

-1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.