Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Multiple Forms - IllegalStateException

 
Frank Manno
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all!
I'm running into a problem with multiple forms in my MIDlet. I have a form that displays items in a recordstore.
From that form, there is a menu with various commands including "Update" and "Add", which when pressed, display the Update and Add form respectively.
The problem I'm having is that I'm being thrown an "IllegalStateException" if I switch from the Main Form to "Add", back to the Main Form and then over to "Update".
Is there something I could be missing? I'm testing this on the emulator (if it makes a difference in debugging the problem).
Any help is appreciated!
Thanks,
Frank
 
James Reilly
wrangler
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have to isolate which method is throwing the
IllegalStateException. Once you know that, the MIDP
(or CLDC) API spec for that method will help you
understand in what situations (and for what reasons)
it can throw that particular exception.
 
Frank Manno
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi James,
Thanks for responding... Can you elaborate a bit on your response. I think I know what you mean, but any further exlanation would be appreciated.
Thanks!
 
James Reilly
wrangler
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, no problem.
If you look at the MIDP 1.0 or 2.0 specification,
(either the JavaDoc or the .pdf) and do a search/grep
for "IllegalStateException" you can see that
different methods might throw an IllegalStateException
for different reasons.
So you have to find out which invocation of a method
in your MIDlet's application code is throwing the
IllegalStateException you are seeing.
You might do this by single-stepping your MIDlet
to gradually narrow down where the IllegalStateException
is being thrown, or compare which methods you use vs.
a "grep" for IllegalStateException in the MIDP specification
to narrow down the candidates, or to try and put some
intelligent debug printlns in your MIDlet, use
try { ... } catch { ... } blocks, or perhaps your IDE will
give you some guidance, etc.
For example in MIDP 2.0, if your application code
had a line like:
...
Spacer spacer = new Spacer(5, 10);
spacer.setLabel("Hello");
...
the call to setLabel would throw an IllegalStateException
always, as spacers must have null labels.
So you have to find what line in your code, the exception
is being thrown and then look at the MIDP spec to see
why the use of some MIDP API method at that line of your
could, might possibly throw an IllegalStateException.
Then, usually the mental lightbulb comes on about what the
problem is.
Hope this helps,
jim
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic