×

Discussion Board

Results 1 to 6 of 6
  1. #1
    Regular Contributor
    Join Date
    Mar 2005
    Posts
    249

    illegal state exception

    Having problems in appending a customItem to a newly created form. I have successfully done this within the rest of the code. No idea why this part should be any different.

    I'm trying to implement a backward navigation. When I initally create the new customItem, I save it. So when I hit "Back" in a diff screen, I try to append that "saved" item onto a new form.

    Code:
    newForm = new Form("Resources", null);
    newForm.addCommand(selectCmd);
    newForm.addCommand(backCmd);
    newForm.addCommand(exitCmd);
    newForm.append(bkList);
    The following exception is thrown at the very last line. (newForm.append(...))

    Uncaught exception: java.lang.IllegalStateException
    - javax.microedition.lcdui.Item.SetParent(), bci=22
    - javax.microedition.lcdui.CustomItem.SetParent(), bci=2
    - javax.microedition.lcdui.Form.Insert(), bci=63
    - javax.microedition.lcdui.Form.append(), bci=15
    - ui.ResourceView.run(), bci=1608
    - java.lang.Thread.run(), bci=11

    The above code is executed in a new thread (hence the run()). bkList is my customItem, that was saved from a previous screen. I have ascertained that it is not null, and contains the correct information.

    Does anyone have any ideas?
    Many thanks.

  2. #2
    Super Contributor
    Join Date
    Mar 2003
    Location
    Israel
    Posts
    2,280
    The javadocs say:
    Throws:
    IllegalStateException - if the item is already owned by a container
    shmoove

  3. #3
    Regular Contributor
    Join Date
    Mar 2005
    Posts
    249
    Sorry. Missed that in the javadoc.
    But I'm still confused... how do I get around that? Would I need to create a clone of the object?

  4. #4
    Regular Contributor
    Join Date
    Mar 2005
    Posts
    249
    Forgot to mention.

    I only get this exception when I run using the s60 fp2 emulator.

    When I run using other emulators, no exception is thrown... but it hangs. It never returns from newForm.append(). When I cancel the operation, it then throws an illegalThreadStateExeption.

    I'm *guessing* that's just emulators being different... But either way, it doesn't work.

    Whatever it is. I'd like to know how to work around it.

    Thanks!
    Last edited by lmtang; 2005-05-25 at 08:38.

  5. #5
    Super Contributor
    Join Date
    Mar 2003
    Location
    Israel
    Posts
    2,280
    I don't have much experience with CustomItems, but from what the javadocs say I'd imagine that if the item has already been append()ed to another form then it will throw the exception, so probably making another instance would solve it.

    shmoove

  6. #6
    Regular Contributor
    Join Date
    Mar 2005
    Posts
    249
    I read your reply, and started wondering if form.deleteAll() would un-append() all the items.

    It does. So I just keep "un-append()ing" it from the form when I'm done to keep it for later reuse.

    Thanks a bunch. I really appreciate the help.

    Cheers.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×