android.view.InflateException: Binary XML file line #12: Error inflating class <unknown>
Posted
技术标签:
【中文标题】android.view.InflateException: Binary XML file line #12: Error inflating class <unknown>【英文标题】: 【发布时间】:2011-05-29 14:50:11 【问题描述】:我收到了许多显示在主题中的错误。这些错误似乎是偶然的,我无法重现它们。从堆栈中我可以了解到,我的不同布局资源可能会发生此类错误。 XML的行也不同。
谁能解释为什么会出现这个错误?我能做些什么来解决这个问题?
堆栈
=============================================================
com.fsp.android.f generated the following exception:
java.lang.RuntimeException: Unable to start activity ComponentInfocom.fsp.android.f/com.life360.android.ui.tour.TourActivity:
--------- Stack trace ---------
1. android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2649)
2. android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2674)
3. android.app.ActivityThread.access$2200(ActivityThread.java:131)
4. android.app.ActivityThread$H.handleMessage(ActivityThread.java:1975)
5. android.os.Handler.dispatchMessage(Handler.java:99)
6. android.os.Looper.loop(Looper.java:123)
7. android.app.ActivityThread.main(ActivityThread.java:4702)
8. java.lang.reflect.Method.invokeNative(Native Method)
9. java.lang.reflect.Method.invoke(Method.java:521)
10. com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
11. com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
12. dalvik.system.NativeStart.main(Native Method)
-------------------------------
----------- Cause -----------
1. android.view.LayoutInflater.createView(LayoutInflater.java:513)
2. com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
3. android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:563)
4. android.view.LayoutInflater.rInflate(LayoutInflater.java:618)
5. android.view.LayoutInflater.rInflate(LayoutInflater.java:621)
6. android.view.LayoutInflater.inflate(LayoutInflater.java:382)
7. android.view.LayoutInflater.inflate(LayoutInflater.java:320)
8. android.view.LayoutInflater.inflate(LayoutInflater.java:276)
9. com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:208)
10. android.app.Activity.setContentView(Activity.java:1629)
11. com.solvek.sample.ui.BaseActivity.onCreate(BaseActivity.java:23)
12. com.solvek.sample.ui.tour.TourActivity.onCreate(TourActivity.java:161)
13. android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
14. android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2587)
15. android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2674)
16. android.app.ActivityThread.access$2200(ActivityThread.java:131)
17. android.app.ActivityThread$H.handleMessage(ActivityThread.java:1975)
18. android.os.Handler.dispatchMessage(Handler.java:99)
19. android.os.Looper.loop(Looper.java:123)
20. android.app.ActivityThread.main(ActivityThread.java:4702)
21. java.lang.reflect.Method.invokeNative(Native Method)
22. java.lang.reflect.Method.invoke(Method.java:521)
23. com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
24. com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
25. dalvik.system.NativeStart.main(Native Method)
-----------------------------
-------- Environment --------
Time =2010-12-20 08:27:35 AM
Device =tmobile/htc_espresso/espresso/espresso:2.1-update1/ERE27/216830:user/release-keys
Make =HTC
Model =T-Mobile myTouch 3G Slide
Product =htc_espresso
App =com.fsp.android.f, version 2.0.9 (build 1232)
这是 XML 的结果,但是在其他 xmls 中也会出现这样的错误
<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android">
<ViewFlipper android:layout_gravity="fill" android:id="@+id/flipper" android:layout_ android:layout_>
<ImageView android:scaleType="fitXY" android:layout_ android:layout_ android:src="@drawable/tour_1"/>
<ImageView android:scaleType="fitXY" android:layout_ android:layout_ android:src="@drawable/tour_2"/>
<ImageView android:scaleType="fitXY" android:layout_ android:layout_ android:src="@drawable/tour_3"/>
<ImageView android:scaleType="fitXY" android:layout_ android:layout_ android:src="@drawable/tour_4"/>
<ImageView android:scaleType="fitXY" android:layout_ android:layout_ android:src="@drawable/tour_5"/>
<ImageView android:scaleType="fitXY" android:layout_ android:layout_ android:src="@drawable/tour_6"/>
<ImageView android:scaleType="fitXY" android:layout_ android:layout_ android:src="@drawable/tour_7"/>
<ImageView android:scaleType="fitXY" android:layout_ android:layout_ android:src="@drawable/tour_8"/>
<ImageView android:scaleType="fitXY" android:layout_ android:layout_ android:src="@drawable/tour_9"/>
<ImageView android:scaleType="fitXY" android:layout_ android:layout_ android:src="@drawable/tour_10"/>
<ImageView android:scaleType="fitXY" android:layout_ android:layout_ android:src="@drawable/tour_11"/>
</ViewFlipper>
<LinearLayout android:id="@+id/exit_bar" android:layout_gravity="top" android:layout_ android:layout_ android:background="@drawable/blue_bar" android:visibility="invisible">
<Button android:background="@drawable/orange_btn" android:layout_ android:layout_ android:layout_gravity="center" android:textStyle="bold" android:textColor="#000000" android:shadowColor="#ffffff" android:shadowRadius="1.6" android:shadowDx="1.5" android:shadowDy="1.3" android:id="@+id/exit_tour_btn" android:text="Exit" android:layout_marginLeft="20dip"/>
<TextView android:layout_ android:textColor="#ffffff" android:layout_gravity="center" android:layout_ android:layout_marginLeft="20dip" android:textSize="16dip" android:textStyle="bold" android:text="Life360 Tour"/>
</LinearLayout>
<Button style="@style/BlueBtn" android:text="Continue" android:layout_marginTop="40dip" android:id="@+id/continue_btn" android:visibility="gone" android:layout_ android:layout_ android:layout_gravity="center" />
<FrameLayout android:id="@+id/bottom_bar" android:layout_gravity="bottom" android:layout_ android:layout_ android:background="@drawable/blue_bar" android:visibility="invisible">
<ImageView android:layout_ android:layout_ android:id="@+id/left" android:layout_gravity="left|center" android:background="@drawable/tour_left" android:layout_marginLeft="10dip"/>
<ImageView android:layout_ android:layout_ android:id="@+id/right" android:layout_gravity="right|center" android:background="@drawable/tour_right" android:layout_marginRight="10dip"/>
</FrameLayout>
</merge>
【问题讨论】:
检查一下。这对我有帮助!***.com/questions/9480972/android-tablelayout-error 【参考方案1】:我通过更新我的应用主题以继承材料组件解决了这个问题。
<style name="Theme.MyApp" parent="Theme.MaterialComponents.DayNight">
<!-- ... -->
</style>
【讨论】:
【参考方案2】:只需移动图像或形状
drawable-v24 到可绘制文件夹
InflateException:
android.view.InflateException: Binary XML file line #32: Error inflating class androidx.appcompat.widget.SearchView
at android.view.LayoutInflater.createView(LayoutInflater.java:633)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at androidx.databinding.DataBindingUtil.inflate(DataBindingUtil.java:126)
at androidx.databinding.DataBindingUtil.inflate(DataBindingUtil.java:95)
at com.foamkart.Fragment.SearchFragment.onCreateView(SearchFragment.kt:37)
【讨论】:
【参考方案3】:如果您正在使用导航组件并尝试膨胀androidx.fragment.app.FragmentContainerView
,请确保在您的导航图上设置startDestination
!
【讨论】:
以上是关于android.view.InflateException: Binary XML file line #12: Error inflating class <unknown>的主要内容,如果未能解决你的问题,请参考以下文章