2

我遇到了异常IllegalStateException

已作为父项添加到经理的字段

当我第二次调用下面的函数时,当我改变微调器的值并且第二次调用这个函数时,我得到了非法状态异常。

这是我的代码:

void showSpinnerDialog(int type) {
    if (_customSpinnerPopup == null) {
        _customSpinnerPopup = new CustomSpinnerPopup();
    }

    UiApplication.getUiApplication().pushModalScreen(_customSpinnerPopup);

    if (_customSpinnerPopup.isSet()) {
        String choice = _customSpinnerPopup.getChoice();
        _editFieldSpinbox.setText(choice);
        getAlbumsForLanguage(choice);
    }
}

private void getAlbumsForLanguage(String choice) {
    language = choice;
    fieldManager.deleteAll();

    final RichList list = new RichList(fieldManager, true, 2, 1);
    songItemsList = new Vector();
    songItemsList = ServerAPI.getNewSongsForLanguage(language, null);
    for (int i = 0; i < songItemsList.size(); i++) {
        SongItem songItem = (SongItem) songItemsList.elementAt(i);
        list.add(new Object[] { bitmap1, songItem.getName(),
            "Artist:" + songItem.getArtist(),
        "Movie: " + songItem.getMovie() });
    }

    add(fieldManager);// **here i am getting exception**
    list.setFocusPolicy(TableController.ROW_FOCUS);

    list.setCommand(new Command(new CommandHandler() {

        public void execute(ReadOnlyCommandMetadata metadata, Object object) {
            SongItem song = (SongItem) songItemsList.elementAt(list.getFocusRow());
            Dialog.alert("exe !" + song.getName());
4

1 回答 1

2

正如异常消息所暗示的那样,您不能多次将 aField或 a Manager(即 a Field)添加到另一个容器中,除非您先将其删除。当你getAlbumsForLanguage()第二次调用时,你会这样调用:

add(fieldManager);// **here i am getting exception**

第二次,这是非法的。要解决这个问题,只需将该行包围:

if (fieldManager.getManager() == null) {
   add(fieldManager);
}
于 2013-04-19T06:38:01.133 回答