3

I've been trying to load a list of records from a database to a screen but there seems to be a problem when the app gets the data and tries to display it on the screen. I read that sometimes this type of error is thrown when displaying large images and such but I have no images and tried some other solutions I've read about. Any input is appreciated!

E/AndroidRuntime: FATAL EXCEPTION: main
  Process: com.blackfrogweb.macrotracker, PID: 16129
  android.view.InflateException: Binary XML file line 23: Binary XML file line 23: Error inflating class <unknown>
  at android.view.LayoutInflater.inflate(LayoutInflater.java:539)
  at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
  at com.blackfrogweb.macrotracker.FavsCustomAdapter.getView(FavsCustomAdapter.java:38)
  at android.widget.AbsListView.obtainView(AbsListView.java:2346)
  at android.widget.ListView.makeAndAddView(ListView.java:1876)
  at android.widget.ListView.fillDown(ListView.java:702)
  at android.widget.ListView.fillFromTop(ListView.java:763)
  at android.widget.ListView.layoutChildren(ListView.java:1671)
  at android.widget.AbsListView.onLayout(AbsListView.java:2148)
  at android.view.View.layout(View.java:16636)
  at android.view.ViewGroup.layout(ViewGroup.java:5437)
  at android.widget.FrameLayout.layoutChildren(FrameLayout.java:336)
  at android.widget.FrameLayout.onLayout(FrameLayout.java:273)
  at android.view.View.layout(View.java:16636)
  at android.view.ViewGroup.layout(ViewGroup.java:5437)
  at android.widget.FrameLayout.layoutChildren(FrameLayout.java:336)
  at android.widget.FrameLayout.onLayout(FrameLayout.java:273)
  at android.view.View.layout(View.java:16636)
  at android.view.ViewGroup.layout(ViewGroup.java:5437)
  at android.widget.FrameLayout.layoutChildren(FrameLayout.java:336)
  at android.widget.FrameLayout.onLayout(FrameLayout.java:273)
  at android.view.View.layout(View.java:16636)
  at android.view.ViewGroup.layout(ViewGroup.java:5437)
  at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1743)
  at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1586)
  at android.widget.LinearLayout.onLayout(LinearLayout.java:1495)
  at android.view.View.layout(View.java:16636)
  at android.view.ViewGroup.layout(ViewGroup.java:5437)
  at android.widget.FrameLayout.layoutChildren(FrameLayout.java:336)
  at android.widget.FrameLayout.onLayout(FrameLayout.java:273)
  at com.android.internal.policy.PhoneWindow$DecorView.onLayout(PhoneWindow.java:2678)
  at android.view.View.layout(View.java:16636)
  at android.view.ViewGroup.layout(ViewGroup.java:5437)
  at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2171)
  at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1931)
  at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1107)
  at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6013)
  at android.view.Choreographer$CallbackRecord.run(Choreographer.java:858)
  at android.view.Choreographer.doCallbacks(Choreographer.java:670)
  at android.view.Choreographer.doFrame(Choreographer.java:606)
  at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:844)
  at android.os.Handler.handleCallback(Handler.java:739)
  at android.os.Handler.dispatchMessage(Handler.java:95)
  at android.os.Looper.loop(Looper.java:148)
  at android.app.ActivityThread.main(ActivityThread.java:5417)
  at java.lang.reflect.Method.invoke(Native Method)
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

Here is the xml of the layout Im trying to "inflate".

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="16dp"
    android:paddingTop="16dp"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:gravity="left">

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

        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:orientation="vertical">

            <TextView
                android:id="@+id/favorite_name"
                android:textColor="@color/colorText"
                android:textSize="?android:attr/textAppearanceMedium"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginBottom="5dp"/>

            <TextView
                android:id="@+id/favorite_cal"
                android:textSize="?android:attr/textAppearanceMedium"
                android:textColor="@color/colorText"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginBottom="5dp"/>

            <TextView
                android:id="@+id/favorite_fat"
                android:textSize="?android:attr/textAppearanceMedium"
                android:textColor="@color/colorText"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="left"
                android:layout_marginBottom="5dp"/>

            <TextView
                android:id="@+id/favorite_carb"
                android:textSize="?android:attr/textAppearanceMedium"
                android:textColor="@color/colorText"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="left"
                android:layout_marginBottom="5dp"/>

            <TextView
                android:id="@+id/favorite_prot"
                android:textSize="?android:attr/textAppearanceMedium"
                android:textColor="@color/colorText"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="left"
                android:layout_marginBottom="5dp"/>

        </LinearLayout>

            <LinearLayout
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:orientation="horizontal"
                android:gravity="right">

                <Button
                    android:id="@+id/add"
                    android:layout_width="40dp"
                    android:layout_height="40dp"
                    android:layout_marginRight="5dp"
                    android:background="@android:drawable/ic_menu_add"/>

                <Button
                    android:id="@+id/edit"
                    android:layout_width="40dp"
                    android:layout_height="40dp"
                    android:layout_marginRight="5dp"
                    android:background="@android:drawable/ic_menu_edit"/>

                <Button
                    android:id="@+id/delete"
                    android:layout_width="40dp"
                    android:layout_height="40dp"
                    android:background="@android:drawable/ic_menu_delete"/>
            </LinearLayout>
    </LinearLayout>

Since I'm not really sure where the error is happening, I'm not sure what piece of code to post -and I don't want to make this unreadable.

2
  • check the Binary XML file line 23 . Commented Jan 13, 2017 at 5:55
  • For other devs this is also cause by xml fonts stackoverflow.com/a/47987602/5710872 Commented Dec 27, 2017 at 6:53

5 Answers 5

4

Currenty you are setting ?android:attr/textAppearanceMedium to android:textSize.
You should replace the attribute with android:textAppearance.

Change

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

TO

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

OR

Set direct value to android:textSizelike

android:textSize="10sp" 
Sign up to request clarification or add additional context in comments.

2 Comments

It works well but I don't know why "android:textSize="?android:attr/textAppearanceMedium" is wrong...?
@TeachMeJava textSize is expecting a size value(px, dp, sp, in and mm). "?android:attr/textAppearanceMedium" is combination of Base text color, typeface, size, and style. So we cannot use it for textsize.
3
android:theme="@style/ThemeOverlay.AppCompat.Dark" 

I removed from my xml file my problem is solved

Comments

0

You have not closed the tag properly.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="16dp"
    android:paddingTop="16dp"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:gravity="left">

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

        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:orientation="vertical">

            <TextView
                android:id="@+id/favorite_name"
                android:textColor="@color/colorText"
                android:textSize="?android:attr/textAppearanceMedium"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginBottom="5dp"/>

            <TextView
                android:id="@+id/favorite_cal"
                android:textSize="?android:attr/textAppearanceMedium"
                android:textColor="@color/colorText"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginBottom="5dp"/>

            <TextView
                android:id="@+id/favorite_fat"
                android:textSize="?android:attr/textAppearanceMedium"
                android:textColor="@color/colorText"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="left"
                android:layout_marginBottom="5dp"/>

            <TextView
                android:id="@+id/favorite_carb"
                android:textSize="?android:attr/textAppearanceMedium"
                android:textColor="@color/colorText"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="left"
                android:layout_marginBottom="5dp"/>

            <TextView
                android:id="@+id/favorite_prot"
                android:textSize="?android:attr/textAppearanceMedium"
                android:textColor="@color/colorText"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="left"
                android:layout_marginBottom="5dp"/>

        </LinearLayout>

        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:orientation="horizontal"
            android:gravity="right">

            <Button
                android:id="@+id/add"
                android:layout_width="40dp"
                android:layout_height="40dp"
                android:layout_marginRight="5dp"
                android:background="@android:drawable/ic_menu_add"/>

            <Button
                android:id="@+id/edit"
                android:layout_width="40dp"
                android:layout_height="40dp"
                android:layout_marginRight="5dp"
                android:background="@android:drawable/ic_menu_edit"/>

            <Button
                android:id="@+id/delete"
                android:layout_width="40dp"
                android:layout_height="40dp"
                android:background="@android:drawable/ic_menu_delete"/>
        </LinearLayout>
    </LinearLayout>

</LinearLayout>

Comments

0

It seems that you are getting the Exception for bellow line of your <TextView/>.

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

Try with

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

Comments

0
private void getDetailFood(String foodId) {
foods.child(foodId).addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
try {
Food food = dataSnapshot.getValue(Food.class);
**Picasso.with(getBaseContext()).load(food.getImage())
                        .into(foodd_image);**
(Iam getting NullPOinter Exception)`enter code here`
collapsingToolbarLayout.setTitle(food.getName());
food_price.setText(food.getPrice());
food_description.setText(food.getDescription());
food_name.setText(food.getName());
}
catch (Exception e)
{
e.printStackTrace();
}

}

1 Comment

pls add some explanation to your solution why this is correct or what you're doing as only code answers are discouraged by stackoverflow

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.