Search code examples
javajava-memidpillegalargumentexceptionlcdui

Choice.IMPLICIT and Choice.EXCLUSIVE in J2ME


Why we can't use Choice.IMPLICIT with in a Form while we can use Choice.EXCLUSIVE. When I use Choice.IMPLICIT, it gives me a java.lang.IllegalArgumentException

 ChoiceGroup msgChoGrp = new ChoiceGroup("", Choice.EXCLUSIVE);

Solution

  • The way you use (mis-use) the MIDP 2 API, IAE is the correct behavior because it is exactly what API javadocs require for ChoiceGroup(String label, int choiceType):

    Throws: IllegalArgumentException - if choiceType is not one of EXCLUSIVE, MULTIPLE, or POPUP

    By the way if all you want is to get rid of radio-buttons and check-boxes, try POPUP kind of ChoiceGroup. If you need to get even closer to implicit List, if you need this really badly, consider CustomItem - though this might require thorough study of API to implement correctly