Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Plural NotFoundException on Huawei phones only

I've noticed many crash reports for my app in production for Huawei phones related exactly to plurals handling. No other phones have this problem but only Huawei.

All plural forms exist and work fine on other devices.

It seems Huawei cannot handle plurals at all:

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

Did anybody have this problem too?

like image 688
makovkastar Avatar asked Nov 10 '14 09:11

makovkastar


1 Answers

I have had this kind of issue according to analytics reports. Same trouble - doesn't have Huawei device.

This had happen on the given list of devices: - Huawei G700-U10 Ascend G700 - Huawei G700-U20 Ascend G700 - Huawei G610-U20 Ascend

Stacktrace:

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) 

I looked at Resources class to clarify the problem and to find any WORKAROUND.

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

According to this code if the plural rule is not found for the given quantity, the plural with rule "OTHER" will be given (before we've got the Exception). I added "other" item (rule) to plural definition in strings.xml. Made update of the app and since then I didn't get any report from this devices list with this kind of exception.

In my case it was in russian locale:

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

It's not the panacea, but it works at least as WORKAROUND.

Happy coding...

like image 94
sky Avatar answered Nov 15 '22 01:11

sky