Android:二进制 XML 文件行错误膨胀类
Posted
技术标签:
【中文标题】Android:二进制 XML 文件行错误膨胀类【英文标题】:Android: Binary XML file line Error inflating class 【发布时间】:2017-05-28 10:42:36 【问题描述】:我一直在尝试将记录列表从数据库加载到屏幕,但是当应用程序获取数据并尝试在屏幕上显示时似乎出现了问题。我读到有时在显示大图像等时会引发这种类型的错误,但我没有图像并尝试了我读过的其他一些解决方案。任何意见表示赞赏!
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_
android:layout_
android:paddingBottom="16dp"
android:paddingTop="16dp"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:gravity="left">
<LinearLayout
android:layout_
android:layout_
android:orientation="horizontal">
<LinearLayout
android:layout_
android:layout_
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:id="@+id/favorite_name"
android:textColor="@color/colorText"
android:textSize="?android:attr/textAppearanceMedium"
android:layout_
android:layout_
android:layout_marginBottom="5dp"/>
<TextView
android:id="@+id/favorite_cal"
android:textSize="?android:attr/textAppearanceMedium"
android:textColor="@color/colorText"
android:layout_
android:layout_
android:layout_marginBottom="5dp"/>
<TextView
android:id="@+id/favorite_fat"
android:textSize="?android:attr/textAppearanceMedium"
android:textColor="@color/colorText"
android:layout_
android:layout_
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_
android:layout_
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_
android:layout_
android:layout_gravity="left"
android:layout_marginBottom="5dp"/>
</LinearLayout>
<LinearLayout
android:layout_
android:layout_
android:layout_weight="1"
android:orientation="horizontal"
android:gravity="right">
<Button
android:id="@+id/add"
android:layout_
android:layout_
android:layout_marginRight="5dp"
android:background="@android:drawable/ic_menu_add"/>
<Button
android:id="@+id/edit"
android:layout_
android:layout_
android:layout_marginRight="5dp"
android:background="@android:drawable/ic_menu_edit"/>
<Button
android:id="@+id/delete"
android:layout_
android:layout_
android:background="@android:drawable/ic_menu_delete"/>
</LinearLayout>
</LinearLayout>
由于我不确定错误发生在哪里,我不确定要发布哪段代码 - 而且我不想让它变得不可读。
【问题讨论】:
检查二进制 XML 文件第 23 行。 对于其他开发人员,这也是由 xml 字体引起的 ***.com/a/47987602/5710872 【参考方案1】:当前您将?android:attr/textAppearanceMedium
设置为android:textSize
。
您应该将属性替换为android:textAppearance
。
改变
android:textSize="?android:attr/textAppearanceMedium"
到
android:textAppearance="?android:attr/textAppearanceMedium"
或
将直接值设置为android:textSize
like
android:textSize="10sp"
【讨论】:
效果很好但是不知道为什么 "android:textSize="?android:attr/textAppearanceMedium" 错了...? @TeachMeJava textSize 需要一个大小值(px、dp、sp、in 和 mm)。 "?android:attr/textAppearanceMedium" 是基本文本颜色、字体、大小和样式的组合。所以我们不能将它用于文本大小。【参考方案2】:android:theme="@style/ThemeOverlay.AppCompat.Dark"
我从我的 xml 文件中删除了我的问题解决了
【讨论】:
【参考方案3】:您没有正确关闭标签。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_
android:layout_
android:paddingBottom="16dp"
android:paddingTop="16dp"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:gravity="left">
<LinearLayout
android:layout_
android:layout_
android:orientation="horizontal">
<LinearLayout
android:layout_
android:layout_
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:id="@+id/favorite_name"
android:textColor="@color/colorText"
android:textSize="?android:attr/textAppearanceMedium"
android:layout_
android:layout_
android:layout_marginBottom="5dp"/>
<TextView
android:id="@+id/favorite_cal"
android:textSize="?android:attr/textAppearanceMedium"
android:textColor="@color/colorText"
android:layout_
android:layout_
android:layout_marginBottom="5dp"/>
<TextView
android:id="@+id/favorite_fat"
android:textSize="?android:attr/textAppearanceMedium"
android:textColor="@color/colorText"
android:layout_
android:layout_
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_
android:layout_
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_
android:layout_
android:layout_gravity="left"
android:layout_marginBottom="5dp"/>
</LinearLayout>
<LinearLayout
android:layout_
android:layout_
android:layout_weight="1"
android:orientation="horizontal"
android:gravity="right">
<Button
android:id="@+id/add"
android:layout_
android:layout_
android:layout_marginRight="5dp"
android:background="@android:drawable/ic_menu_add"/>
<Button
android:id="@+id/edit"
android:layout_
android:layout_
android:layout_marginRight="5dp"
android:background="@android:drawable/ic_menu_edit"/>
<Button
android:id="@+id/delete"
android:layout_
android:layout_
android:background="@android:drawable/ic_menu_delete"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
【讨论】:
【参考方案4】:您的<TextView/>
的波纹管似乎是Exception
。
android:textSize="?android:attr/textAppearanceMedium"
试试
android:textAppearance="?android:attr/textAppearanceMedium"
【讨论】:
【参考方案5】: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();
【讨论】:
请为您的解决方案添加一些解释,为什么这是正确的,或者您正在做什么,因为 *** 不鼓励只回答代码以上是关于Android:二进制 XML 文件行错误膨胀类的主要内容,如果未能解决你的问题,请参考以下文章
android.view.inflateexception 二进制 xml 文件第 1 行错误膨胀类 android.widget.relativeLayout
android.view.InflateException:二进制 XML 文件第 15 行:二进制 XML 文件第 19 行:膨胀类片段时出错
二进制 XML 文件第 1 行:Xamarin Android 中 Google Maps 的类片段错误膨胀错误
android.view.InflateException 膨胀类片段时出错,二进制 XML 文件第 1 行?
膨胀类 ImageView 时出错 - android.view.InflateException:二进制 XML 文件第 10 行:膨胀类 ImageView 时出错
Google Map API 问题:android.view.InflateException:二进制 XML 文件第 2 行:二进制 XML 文件第 2 行:膨胀类片段时出错