【问题标题】:Xamarin Android Fragment Inflation, Binary XML file line #1: Binary XML file line #1: Error inflating class fragmentXamarin Android Fragment Inflation, Binary XML file line #1: Binary XML file line #1: Error inflating class fragment
【发布时间】:2019-03-19 19:49:38
【问题描述】:

我一直在关注一本关于 Xamarin Android 开发的书,但在对片段进行膨胀时遇到了问题。错误消息指出 “二进制 XML 文件第 1 行:二进制 XML 文件第 1 行:膨胀类片段时出错”。此错误在 ListFragment 的 Activity 的 OnCreate 中出现。如果有人希望查看我已将 PoiListActivity 包装在 try catch 块中以获取此错误的代码。 据我所知,我的布局具有正确的 axml,并且我没有收到任何构建错误,表明 C# 代码很好。如果有人能够提供帮助,我将不胜感激,因为我已经头疼了几天,这阻碍了我进一步学习。

代码可以找到here

被关注的书是this

【问题讨论】:

    标签: android-fragments xamarin xamarin.android


    【解决方案1】:

    要获得有关正在发生的事情的更多信息,最好输出整个异常,而不仅仅是它的消息。或者简单地删除 try/catch 块以查看调试输出中的完整错误。内部异常告诉我们:

    Android.Views.InflateException: Binary XML file line #1: Error inflating class fragment ---> 
    Java.Lang.RuntimeException: Content has view with id attribute 'android.R.id.list' that is not a ListView class
    

    这意味着您需要将android:id="@android:id/list" 添加到 PoiListFragment.axml 中的 ListView 中。更多信息请见here

    下次提问时,请提供更多信息,例如指明文件名,包括一些代码等。

    【讨论】:

    • 嗨,这已经解决了这个问题。我想知道您是否可以解释为什么“@android:id/list”有效但“_@+id/list”无效。我的印象是第二个只是简单地添加了 id,如果它不存在,否则它使用该 ID(都连接到列表片段中的列表视图)。这仅仅是 List Fragments 独有的东西还是我错过了什么?
    • @AdamParker 这在屏幕布局部分下的ListFragment docs 中有解释。基本上,@android:id/list 和你定义的 id 不一样。在构建过程中,所有 id 都会转换为唯一的数字。
    猜你喜欢
    • 1970-01-01
    • 2016-07-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-13
    • 1970-01-01
    • 2014-01-22
    • 1970-01-01
    相关资源
    最近更新 更多