我注意到我的应用程序在华为手机的生产中发现了许多崩溃报告,这些报告与复数处理完全相关。没有其他手机有这个问题,只有华为。
所有复数形式都存在并在其他设备上正常工作。
似乎华为根本无法处理复数:
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)
...
是否有人也有这个问题?
答案 0 :(得分:1)
根据分析报告,我遇到过这种问题。同样的问题 - 没有华为设备。
这发生在给定的设备列表上: - 华为G700-U10 Ascend G700 - 华为G700-U20 Ascend G700 - 华为G610-U20 Ascend
堆栈跟踪:
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中将“其他”项(规则)添加到复数定义中。更新了应用程序,从那时起,我没有从这个设备列表中获得任何报告,但有这种例外。
就我而言,它是俄语语言环境:
<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>
这不是灵丹妙药,但它至少可以作为替代方法。
快乐的编码......