ListFragment RuntimeException'android.R.id.list'丢失 [英] ListFragment RuntimeException 'android.R.id.list' missing

查看:86
本文介绍了ListFragment RuntimeException'android.R.id.list'丢失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

编辑1/16/2013:问题已解决!两天前,我发布了该应用程序的更新版本,并使用android:id="@android:id/list正确地正确地标识了ListViews.确实,抛出的异常具有误导性,与实际问题无关...

Edit 1/16/2013: Problem Resolved! Two days ago, I released an updated version of the app and correctly identified the ListViews as I had originally done, by using android:id="@android:id/list. Really though, the exception being thrown was misleading and that had nothing to do with the actual problem...

当我实施Sean关于通过将null传递给ViewGroup来扩大ListFragment视图的建议时,真正的解决方案就来了.我没有从新版本收到相同的异常,并且足够的设备已经下载了新版本,可以放心地说此问题已解决.但是,我非常感谢劳伦斯的评论和回答,并将继续阅读有关他如何实例化片段的信息.虽然他提供了将零值传递给View充气机的建议,但实际上肖恩是第一个这样做的人,由于他的解决方案似乎已经解决了该问题,因此将相应地给予赏金.如果我学习/阅读更多有关劳伦斯出色答案所建议的实例化片段的方法的信息,我将在以后更新此线程.太糟糕了,我无法分割赏金!

The real fix came when I implemented the suggestions by Sean on inflating the ListFragment views by passing null to the ViewGroup. I have not received the same Exception from the new version, and the new version has been downloaded by enough devices to safely say this issue is resolved. However I really appreciate the comments and answer made by Lawrence, and will continue to read about how he is instantiating the Fragments. While he provided the suggestion of passing null to the View inflater, Sean was actually the first to do so, and since his solution seems to have resolved the issue, the bounty will be awarded accordingly. I will update this thread in the future if I learn/read more about the different ways of instantiating the Fragments as suggested by Lawrence's excellent answer. Too bad I can't split the bounty!

编辑1/14/2013::与ListView相关的XML文件位于 http ://pastebin.com/2xnG1VfF (根据@LawrenceChoy的请求)

Edit 1/14/2013: ListView related XML files are located at http://pastebin.com/2xnG1VfF per @LawrenceChoy's request

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

Edit 1/13/2013: I released an updated version of my app and used android:id="@+id/android:list instead of android:id="@android:id/list" per Bishan's suggestion, however I am still receiving random exceptions that my Fragment Actvity does not have a ListView whose id attribute is 'android.R.id.list', even though that activity does not have any ListViews. Added another exception from LGE phone.

编辑1/9/2013:尽管碧山提供了一个答案,但我希望对他的解决方案为什么可以防止此异常进行更多的解释.进一步阅读后,我相信这是因为使用自定义ListView时,应使用+符号.但是想得到确认,我是正确的或得到澄清,特别是考虑到两者似乎都可以在许多不同的设备和仿真器上工作.在大约20分钟内提出赏金,以寻求有关此事的可靠来源/答案.谢谢.

Edit 1/9/2013: Although Bishan provided an answer, I was hoping for a little more explanation as to why his solution might prevent this exception. After reading further I believe it is because when using a custom ListView, one should use a + symbol. However would like to get confirmation I am correct or to get clarification, especially considering both seem to work on many different devices and emulators. Raising a bounty in about 20 minutes to seek a reputable source/answer on the matter. Thanks.

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

I'm getting some very odd behavior from a few devices out in the wild after a recent updated release to the play store.

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

In my new release I have a FragmentActivity (called TabsStyled) that uses a FragmentStatePagerAdapter to manage several fragments. I have a total of 4 fragments, and 2 of those fragments extend ListFragment and have listviews populated by LoaderManager and CursorLoader, all from support.v4 libraries. The other two fragments do not have ListViews and do not extend ListFragment.

我在多个设备以及AVD上进行了广泛的测试,但从未遇到任何由于缺少android.R.id.list而引起的RuntimeExceptions.

I did extensive testing on multiple devices as well as AVDs and never encountered any RuntimeExceptions for missing android.R.id.list.

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

However, upon release, a few ACRA crashes showed up for the FragmentAcitivty "Your content must have a ListView whose id attribute is 'android.R.id.list'". TabsStyled.class is the FragmentActivity that manages the ListFragments and itself does not have any `ListViews'. This seems very strange to me, since I would think that if this exception were to be thrown, it should be for one of the ListFragments, and not the "parent" FragmentActivity.

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

Here's the top of the stack trace, and I'm happy to provide any additional code or info as requested rather than paste everything here.

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'

可在pastebin上找到完整的堆栈跟踪信息: http://pastebin.com/aiV7pwXP .

A full stack trace available on pastebin here: http://pastebin.com/aiV7pwXP.

每个包含ListViews的ListFragments的XML(每个ListFragment的单独XML中的单独ListView):

The XML for each of the ListFragments which contain the ListViews (a separate ListView in a separate XML for each 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" />

其中一个ListFragments(略微简化,以便于诊断)上载到pastebin(另一个ListFragment非常相似):

One of the ListFragments (slightly simplified to make this easier to diagnose) uploaded to pastebin (the other ListFragment is very similar): http://pastebin.com/Nts3nVx1

以及TabsStyled(FragmentActivity)的稍微简化的完整版本: http://pastebin.com/ZS4Xg8kP

And a slightly simplified full version of TabsStyled (FragmentActivity): http://pastebin.com/ZS4Xg8kP

到目前为止,已创建异常的设备(从1/14开始,它们继续发布崩溃):

The devices that created the exceptions thus far (and as of 1/14 they continue to post crashes):

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)

推荐答案

只是预感,但是请尝试在不使用ViewGroup的情况下为ListFragment扩展自定义视图.因此,在您的ListFragment中更改

Just a hunch, but try inflating your custom View for your ListFragment without using the ViewGroup. So in your ListFragment change

View logv = inflater.inflate(R.layout.listroot, container, false);

View logv = inflater.inflate(R.layout.listroot, null);

这篇关于ListFragment RuntimeException'android.R.id.list'丢失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆