ListFragment RuntimeException的“android.R.id.list'失踪(解决) [英] ListFragment RuntimeException 'android.R.id.list' missing (resolved)

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

问题描述

修改2013年1月16日:解决掉!前两天,我发布了应用程序的更新版本和正确确定的列表视图因为我原本做的,通过使用 Android的:ID =@机器人:ID /列表真的不过,异常被抛出被误导,无关与实际问题...

真正的修复来了,当我实现的建议由Sean上传递充气 ListFragment 欣赏到的ViewGroup 。我还没有收到新版本相同的异常,而新版本已经通过足够的设备下载到有把握地说这个问题解决了。不过,我真的AP preciate的意见,回答劳伦斯做,并将继续了解他是如何实例化片段。虽然他提供的传球空到View吹气的建议,肖恩实际上是第一个这样做的,而且由于他的解决方案似乎已经解决了这个问题,赏金将相应奖励。如果我知道我将在未来更新此线程/阅读更多有关实例化片段由劳伦斯的出色答卷的建议的不同方式。可惜我不能分割赏金!

修改2013年1月14日: 的ListView 相关 XML 文件位于 http://pastebin.com/2xnG1VfF 每@ LawrenceChoy的要求

修改2013年1月13日:我公布我的应用程序的更新版本,并使用机器人:ID =@ + ID /安卓列表而不是机器人:ID =@机器人:ID /列表每璧山的建议,但我仍然接受我的片段Actvity没有随机异常一个ListView的id属性是'android.R.id.list,即使该行为不具有任何列表视图添加另一个异常从LG电子手机。

修改2013年1月9日:虽然璧山给出了一个答案,我希望多一点解释,为什么他的解决方案可能prevent此异常。进一步阅读后,我相信这是使用自定义的时候,因为的ListView ,应该使用一个+号。但是想获得确认我是正确的或获得澄清,尤其是考虑似乎都在许多不同的设备和仿真工作。在大约20分钟提高赏金,寻求对此事有信誉的来源/答案。谢谢你。


我碰到了一些设备一些非常奇怪的行为在野外最近更新发布到Play商店之后。

在我的新版本我有一个 FragmentActivity (称为TabsStyled),它使用 FragmentStatePagerAdapter 来管理多个片段。我一共有4个片段,而这些片段2延长 ListFragment 并通过 LoaderManager 填充列表视图和 CursorLoader ,全部由 support.v4 库。另外两个片段没有列表视图,不延长 ListFragment

我做了多台设备以及自动真空淀积系统广泛的测试,从来没有遇到过任何RuntimeExceptions失踪android.R.id.list。

然而,一经推出,少数ACRA崩溃露面的FragmentAcitivty 您的内容必须有一个ListView的id属性是'android.R.id.list'。 TabsStyled.class是 FragmentActivity 管理​​该ListFragments和它本身没有任何`列表视图。这似乎很奇怪,我,因为我认为,如果该异常被抛出,这应该是ListFragments之一,而不是父母FragmentActivity。

下面是堆栈跟踪的顶部,我很乐意提供任何额外的code或信息的要求,而不是贴在这里的一切。

 了java.lang.RuntimeException:无法启动活动ComponentInfo {com.myapp.hiddenforsecurity / com.myapp.hiddenforsecurity.TabsStyled}:
了java.lang.RuntimeException:您的内容必须有一个ListView的id属性是'android.R.id.list

在这里引擎收录提供一个完整的堆栈跟踪: http://pastebin.com/aiV7pwXP

该XML为每个 ListFragments 包含的列表视图(单独的的ListView 为每个单独的XML ListFragment

 < ListView的机器人:ID =@机器人:ID /列表
    !< - 释放目前使用@ + ID /安卓名单) - GT;
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =0dip
    机器人:layout_weight =45/>

其中的 ListFragments (略简化,以使这更容易诊断)上传到引擎收录(其他ListFragment非常相似)的 http://pastebin.com/Nts3nVx1

和TabsStyled的略为简化完整版( FragmentActivity ): HTTP ://pastebin.com/ZS4Xg8kP

这创造了例外迄今(并作为1/14他们继续发布崩溃)的设备:

 型号品牌ANDROID API
GT-I9305三星4.1.1(使用@android:ID /列表)
GT-S7562三星4.0.4(使用@android:ID /列表)
GalaxyNexus三星4.2.1(带@ + ID /安卓看到同样的异常:清单)
L-01E LGE 4.0.4(相同的异常见过@ + ID /安卓名单)


解决方案

只是一个预感,但尝试充气自定义视图为您ListFragment不使用的ViewGroup。因此,在您ListFragment变化

 查看logv = inflater.inflate(R.layout.listroot,集装箱,FALSE);

 查看logv = inflater.inflate(R.layout.listroot,NULL);

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...

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!

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

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.

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.


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

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.

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

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'

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

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" />

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

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

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)

解决方案

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);

to

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

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

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