ListFragment RuntimeException'android.R.id.list'缺失

log*_*ray 0 android android-listfragment android-fragmentactivity

编辑2013年1月16日:问题已解决!两天前,我发布了应用程序的更新版本,并通过使用正确识别了ListViews我原来所做的android:id="@android:id/list.实际上,抛出的异常是误导性的,与实际问题无关......

真正的解决方案来自于我实施了肖恩关于ListFragment通过传递null给观点来夸大观点的建议ViewGroup.我没有从新版本收到相同的Exception,新版本已被足够的设备下载,以确保此问题得到解决.但是我非常感谢劳伦斯的评论和回答,并将继续阅读他如何实例化片段.虽然他提出了将null传递给View inflater的建议,但Sean实际上是第一个这样做的,并且由于他的解决方案似乎已经解决了这个问题,所以奖金将相应地颁发.如果我学习/阅读更多关于实例化片段的不同方法,我会在将来更新这个帖子,正如劳伦斯的出色答案所建议的那样.太糟糕了我不能分裂赏金!

编辑2013年1月14日: 根据@ LawrenceChoy的要求,ListView相关XML文件位于http://pastebin.com/2xnG1VfF

编辑 2013年1月13日:我发布了我的应用程序的更新版本,android:id="@+id/android:list而不是android:id="@android:id/list"根据Bishan的建议使用,但我仍然收到我的Fragment Actvity没有的随机例外a ListView whose id attribute is 'android.R.id.list',即使该活动没有任何ListViews.LGE手机增加了另一个例外.

编辑2013年1月9日:虽然碧山提供了答案,但我希望能更多地解释为什么他的解决方案可能会阻止这种异常.在进一步阅读之后,我相信这是因为在使用自定义时ListView,应该使用+符号.但是我希望得到确认我是正确的或得到澄清,特别是考虑到两者似乎都适用于许多不同的设备和模拟器.在大约20分钟内筹集赏金以寻求有关此事的信誉良好的来源/答案.谢谢.


在最近更新发布到Play商店后,我从一些设备中获得了一些非常奇怪的行为.

在我的新版本中,我有一个FragmentActivity(称为TabsStyled),它使用a FragmentStatePagerAdapter来管理多个片段.我总共有4个片段,其中2个片段扩展ListFragment并且列出了由LoaderManager和填充的列表视图CursorLoader,所有这些片段都来自support.v4库.其他两个片段没有也ListViews没有延伸ListFragment.

我在多个设备和AVD上进行了大量测试,并且从未遇到任何缺少android.R.id.list的RuntimeExceptions.

然而,一旦发布,一些ACRA崩溃就出现在FragmentAcitivty上"Your content must have a ListView whose id attribute is 'android.R.id.list'".TabsStyled.class是FragmentActivity管理ListFragments的,它本身没有任何`ListViews'.这对我来说似乎很奇怪,因为我认为如果抛出这个异常,它应该是一个ListFragments,而不是"父"FragmentActivity.

这是堆栈跟踪的顶部,我很乐意按要求提供任何其他代码或信息,而不是在此处粘贴所有内容.

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.myapp.hiddenforsecurity/com.myapp.hiddenforsecurity.TabsStyled}: 
java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
Run Code Online (Sandbox Code Playgroud)

这里有一个完整的堆栈跟踪:http://pastebin.com/aiV7pwXP.

每个ListFragments包含ListViews的ListViewXML(每个都是单独的XML ListFragment):

<ListView android:id="@android:id/list" 
    <!--the release currently uses "@+id/android:list)-->
    android:layout_width="fill_parent" 
    android:layout_height="0dip" 
    android:layout_weight="45" />
Run Code Online (Sandbox Code Playgroud)

ListFragments上传到pastebin的其中一个(略微简化以使其更易于诊断)(其他ListFragment非常相似):http://pastebin.com/Nts3nVx1

并略微简化了TabsStyled(FragmentActivity)的完整版本:http://pastebin.com/ZS4Xg8kP

到目前为止创建异常的设备(截至1/14他们继续发布崩溃):

MODEL       BRAND    ANDROID API
GT-I9305    Samsung  4.1.1 (using @android:id/list)
GT-S7562    Samsung  4.0.4 (using @android:id/list)
GalaxyNexus Samsung  4.2.1 (same exception seen with @+id/android:list)
L-01E       LGE      4.0.4 (same exception seen with @+id/android:list)
Run Code Online (Sandbox Code Playgroud)

Sea*_*eil 5

只是预感,但尝试在不使用ViewGroup的情况下为ListFragment充气自定义View.所以在ListFragment中更改

View logv = inflater.inflate(R.layout.listroot, container, false);
Run Code Online (Sandbox Code Playgroud)

View logv = inflater.inflate(R.layout.listroot, null);
Run Code Online (Sandbox Code Playgroud)