我收到异常IllegalStateException
:
Field added to a manager while it is already parented
当我第二次调用下面的函数时,当我更改微调器的值并且第二次调用该函数时,我收到非法状态异常。
这是我的代码:
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());
最佳答案
正如异常消息所示,您不能将 Field
或 Manager
(这是一个 Field
)添加到另一个容器,超过一次,除非您先将其删除。当您第二次调用 getAlbumsForLanguage()
时,您将调用:
add(fieldManager);// **here i am getting exception**
第二次,这是非法的。要解决这个问题,只需将该行括起来:
if (fieldManager.getManager() == null) {
add(fieldManager);
}
关于java - 非法状态异常:Field added to a manager while it is already parented,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16098467/