Multiple NotFoundException only on Huawei phones

I noticed a lot of crash reports for my production application for Huawei phones, related exactly to plural processing. Other phones do not have this problem, except for Huawei.

All multiple forms exist and work great on other devices.

Huawei seems to not be able to 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) ... 

Has anyone had this problem too?

+5
source share
1 answer

I had such a problem according to analyst reports. The same problem - there is no Huawei device.

This happened in this 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 the Resources class to clarify the problem and 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 a plural rule is not found for a given value, a plural will be indicated with the rule "OTHER" (before we get the Exception). I added a "different" element (rule) to the plural definition in the strings.xml file. The application was updated, and since then I have not received any report from this list of devices with this exception.

In my case, it was in Russian:

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

This is not a panacea, but it works at least as a WORKAROUND.

Happy coding ...

+1
source

Source: https://habr.com/ru/post/1206552/


All Articles