我得到例外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());
答案 0 :(得分:2)
正如异常消息所示,除非先将其删除,否则您不能多次将Field
或Manager
(Field
)添加到其他容器中。当您第二次致电getAlbumsForLanguage()
时,您会将其称为:
add(fieldManager);// **here i am getting exception**
第二次,这是非法的。要解决这个问题,请使用以下内容包围该行:
if (fieldManager.getManager() == null) {
add(fieldManager);
}