华为手机上出现的复数NotFoundException问题

6
我注意到我的应用在华为手机上的生产中有许多崩溃报告与复数处理相关。其他手机没有这个问题,只有华为手机。
所有的复数形式在其他设备上都存在并��正常工作。
似乎华为完全不能处理复数形式:
android.content.res.Resources$NotFoundException: Plural resource ID #0x7f060000 quantity=4 item=few
       at android.content.res.Resources.getQuantityText(Resources.java:290)
       at android.content.res.Resources.getQuantityString(Resources.java:397)
       ...

android.content.res.Resources$NotFoundException: Plural resource ID #0x7f060000 quantity=6 item=many
       at android.content.res.Resources.getQuantityText(Resources.java:290)
       at android.content.res.XResources.getQuantityText(XResources.java:667)
       at android.content.res.Resources.getQuantityString(Resources.java:397)
       ...

有人也遇到过这个问题吗?


@Czechnology 不,它也发生在Android 4.+上。 - makovkastar
找到任何解决方案了吗?我无法在任何设备或模拟器上重现这个问题。 - Czechnology
我没有任何华为设备进行测试,因此无法重现。关于您在N7上的情况 - 也许您忘记为某些复数指定字符串了? - makovkastar
不,我真的很困惑——这个应用已经发布了大约四个月,有超过一千个用户使用,但从未收到过这种错误报告。 - Czechnology
这可能是由于不良或不支持的语言,如俄语、捷克语等。这个问题提到了这个问题,并引用了此Google问题的第15条评论 - Sufian
显示剩余2条评论
1个回答

2

根据分析报告,我曾遇到过这种问题。同样的麻烦事 - 没有华为设备。

在以下设备清单上发生了这种情况: - 华为G700-U10升 G700 - 华为G700-U20升 G700 - 华为G610-U20升

堆栈跟踪:

android.content.res.Resources$NotFoundException: Plural resource ID #0x7f0d0000 quantity=5 item=many
    at android.content.res.Resources.getQuantityText(Resources.java:290)
    at android.content.res.Resources.getQuantityString(Resources.java:397)
    at com.sixthsensegames.client.android.app.activities.TournamentInfoActivity2$a$1.run(SourceFile:2233)
    at android.os.Handler.handleCallback(Handler.java:725)
    at android.os.Handler.dispatchMessage(Handler.java:92)
    at android.os.Looper.loop(Looper.java:153)
    at android.app.ActivityThread.main(ActivityThread.java:5341)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:929)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:696)
    at dalvik.system.NativeStart.main(Native Method) 

我查看了Resources类来澄清问题并找到任何解决方法。

public CharSequence getQuantityText(@PluralsRes int id, int quantity)
        throws NotFoundException {
    NativePluralRules rule = getPluralRule();
    CharSequence res = mAssets.getResourceBagText(id,
            attrForQuantityCode(rule.quantityForInt(quantity)));
    if (res != null) {
        return res;
    }
    res = mAssets.getResourceBagText(id, ID_OTHER);
    if (res != null) {
        return res;
    }
    throw new NotFoundException("Plural resource ID #0x" + Integer.toHexString(id)
            + " quantity=" + quantity
            + " item=" + stringForQuantityCode(rule.quantityForInt(quantity)));
}

根据这段代码,如果没有找到给定数量的复数规则,则会使用带有规则“OTHER”的复数(在我们得到异常之前)。我在strings.xml中添加了“other”项(规则)到复数定义中。更新了应用程序后,自那以后我就没有收到任何来自这些设备列表的此类异常报告。在我的情况下,这是在俄语区域设置中发生的。
<plurals name="career_tournament_goal_wins_left">
    <item quantity="one">осталась %1$s победа</item>
    <item quantity="few">осталось %1$s победы</item>
    <item quantity="many">осталось %1$s побед</item>
    <item quantity="other">осталось %1$s побед</item> <!-- for Huawei G700-u20 -->
</plurals>

这不是万能解决方案,但至少可以作为一种解决方法。

愉快的编码...


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接