Issue
I'm fetching a color like this and it is returning 0 for a few devices that I'm seeing on crash reports. They are all in res/values/colors.xml. Ex. <color name="firstcolor">#A8A77A</color>. The colorString is dynamic.
int primaryColor = ContextCompat.getColor(context,
context.getResources().getIdentifier(colorString.toLowerCase(),
context.getString(R.string.color), context.getPackageName()));
I've tested on these devices and it works: LG G5 (7.0) - Nokia N1 (5.1.1) - Motorola G (5.1) - Samsung Core Prime (4.4.4)
The crash reports are from these: Samsung Ace 4 (4.4.2) - Sony Xperia M5 E5603 (6.0) - NG Envy (4.4.2)
Fatal Exception: android.content.res.Resources$NotFoundException: Resource ID #0x0
at android.content.res.Resources.getValue(Resources.java:1133)
at android.content.res.Resources.getColor(Resources.java:815)
at android.support.v4.content.ContextCompat.getColor(ContextCompat.java:434)
Any way to find out why it doesn't work for some of these devices?
Solution
Turns out the issue was toLowerCase(). A capital I was being transformed to a ı instead of i for some Locales, which resulted in not being able to find the resource by identifier.
Answered By - ono
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.