Your main mistake here is I think not using appropriate logging in your MIDlet. That makes debugging of the issues like you describe unnecessary complicated. mistakes in the code snippet you posted.
- With logging done right (refer here for details if you're interested), you could simply run your midlet in emulator and check console messages to find out whether expected code.
From the code snippet you posted and your explanations it looks like intBloggerLength
value is not constant. Coupled with the way how you invoke ChoiceGroup constructor in the line you mention as problematic, this looks a sure way to get IllegalArgumentException
.
- You could find that out yourself if you'd wrap this line into
try-catch
and put appropriate logging code into catch block but since you didn't do that, we have to merely guess. Note if you test in emulator, there is also a chance for exception message and stack trace to be shown in its console.
To find out how you could get that exception, refer to API javadocs for the constructor you use:
Throws:
...IllegalArgumentException
- if the imageElements
array is non-null and has a different length from the stringElements array...
There are three other possible reasons for exception to be thrown listed in API docs, but I'll focus on one where your code snippet looks very slippery.
Let's look back at your code, images array length is 6: {null, null, null, null, null, null}
- this means as soon as intBloggerLength
differs from 6, this will throw IAE.
To fix this, simplest way would be to pass null
value instead of images array. Or, if you need the array to be not null, just write the code so that it has valid length, eg
new Image[menuItems.length]