Android:二进制XML文件行错误膨胀类

时间:2017-01-13 05:52:16

标签: android xml layout binary inflate-exception

我一直在尝试将数据库中的记录列表加载到屏幕上,但是当应用获取数据并尝试在屏幕上显示时,似乎存在问题。我读到有时这种类型的错误在显示大图像时会抛出,但我没有图像,并尝试了一些其他我已经读过的解决方案。任何意见都表示赞赏!

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)

这是我试图“膨胀”的布局的xml。

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

由于我不确定错误发生在哪里,我不确定要发布什么代码 - 而且我不想让它变得不可读。

5 个答案:

答案 0 :(得分:4)

目前您将?android:attr/textAppearanceMedium设为android:textSize 您应该使用android:textAppearance替换该属性。

  

更改

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

TO

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

OR

将直接值设置为android:textSize,如

android:textSize="10sp" 

答案 1 :(得分:3)

android:theme="@style/ThemeOverlay.AppCompat.Dark" 

我从我的xml文件中删除了我的问题已解决

答案 2 :(得分:0)

您尚未正确关闭代码。

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

答案 3 :(得分:0)

您似乎正在Exception获得<TextView/>下方的 android:textSize="?android:attr/textAppearanceMedium"

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

尝试

string replyText = "I am not yet ready to answer this question. Please choose another option.";

            switch (appointmentBookType){
                case Option1:
                    //Call Option1 Dialog.
                    break;
                case Option2:
                    //Call Option2 Dialog.
                    break;

答案 4 :(得分: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();
}

}