我注意到我的应用程序在华为手机上的许多崩溃报告都与复数处理完全相关。除了华为,其他手机都没有这个问题。
所有复数形式都存在,并且在其他设备上工作正常。
华为似乎根本不能处理复数:
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)
...有没有人也有这个问题?
发布于 2016-10-07 18:40:40
根据分析报告,我遇到过这种问题。同样的问题--没有华为设备。
这发生在给定的设备列表上:- Huawei G700-U10 Ascend G700 - Huawei G700-U20 Ascend G700 - Huawei 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) 我查看了参考资料类,以澄清问题并找到任何解决方法。
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>这不是灵丹妙药,但它至少可以作为变通方法。
快乐的编码...
https://stackoverflow.com/questions/26840732
复制相似问题