iOS Crashes when calling Enum.valueOf(String arg0)?

53 views
Skip to first unread message

mikko.nu...@gmail.com

unread,
Dec 15, 2014, 8:44:50 AM12/15/14
to codenameone...@googlegroups.com
Hi,

might there something wrong with iOS enumeration code? Calling Enumeration.valueOf(String arg0) seems to cause unhandled NullPointerException even if embedded in try - catch block (and seemed that there was a correct enumeration value also) and cause an application crash:

try {                
     projectItem
.setProjectStatus(ProjectStatus.valueOf(getContentFromChildElement(project, "status")));  
} catch (Exception e) {                
     projectItem
.setProjectStatus(ProjectStatus.NONE);
}

This worked in simulator.

mall...@gmail.com

unread,
Dec 15, 2014, 10:44:30 AM12/15/14
to codenameone...@googlegroups.com, mikko.nu...@gmail.com
 
The is a known, yet unacknowledged bug:

https://code.google.com/p/codenameone/issues/detail?id=1188

Shai Almog

unread,
Dec 15, 2014, 11:12:16 AM12/15/14
to codenameone...@googlegroups.com, mikko.nu...@gmail.com, mall...@gmail.com
That's a bit problematic with enums. Since valueOf uses a form of reflection to instantiate the objects its problematic on the devices.
This should be a problem on Android too due to the obfuscation process, it might work for simple test cases but I think it will fail for dynamic data.

The workaround is to put a name into every enum entry then create your own parse file that compares the name to the given string.

mikko.nu...@gmail.com

unread,
Dec 16, 2014, 4:08:45 AM12/16/14
to codenameone...@googlegroups.com, mikko.nu...@gmail.com, mall...@gmail.com
Okay, thanks. I had a feeling this would be the reason.




Reply all
Reply to author
Forward
0 new messages