在另一个管理器中添加垂直字段管理器时出现IllegalStateException

时间:2013-06-03 12:59:55

标签: blackberry blackberry-simulator blackberry-eclipse-plugin blackberry-jde

我正在尝试在 VerticalFieldManager 中添加一个列表,然后将该管理器添加到另一个 VerticalFieldManager 。我在自定义选项卡中使用它。第一次在应用程序启动时它运行正常但是当我切换到另一个选项卡并返回到它时它会给出 IllegalStateException

我在很多方面尝试了它,但没有在添加VerticalFieldManager时得到导致异常的原因。

我正在使用代码:

//HEADER
_bitmap = EncodedImage.getEncodedImageResource("Friends.png");
friendsBmp = new BitmapField(Constants.sizePic(_bitmap, _bitmap.getHeight(), _bitmap.getWidth()));

//add(WebBitmapField.getUrlHFM());
SCREEN_FLAG = Constants.FRIENDS_FLAG ;

//FRIENDS' UPPER TAB    
friendsTabHFM =new HorizontalFieldManager();

Bitmap ConnectedUser_normal_Bmp =Constants.sizePic(EncodedImage.
        getEncodedImageResource("connected_user_normal.png"),40, Display.getWidth()/2); //Bitmap.getBitmapResource("connected_user_normal.png");
Bitmap search_normal_Bmp = Constants.sizePic(EncodedImage.
        getEncodedImageResource("search_normal.png"),40, Display.getWidth()/2);//Bitmap.getBitmapResource("search_normal.png");

Bitmap ConnectedUser_tap_Bmp = Constants.sizePic(EncodedImage.
        getEncodedImageResource("connected_user_tap.png"),40, Display.getWidth()/2);//Bitmap.getBitmapResource("connected_user_tap.png");
Bitmap search_tap_Bmp = Constants.sizePic(EncodedImage.
        getEncodedImageResource("search_tap.png"),40, Display.getWidth()/2);//Bitmap.getBitmapResource("search_tap.png");

connectedUsersTab= new CustomButtonField(ConnectedUser_normal_Bmp.getWidth(), "", ConnectedUser_normal_Bmp, ConnectedUser_tap_Bmp, ButtonField.FIELD_HCENTER );
connectedUsersTab.setChangeListener(this);

searchTab = new CustomButtonField(search_normal_Bmp.getWidth(), "", search_normal_Bmp, search_tap_Bmp, ButtonField.FIELD_RIGHT);
searchTab.setChangeListener(this);


friendsTabHFM.add(connectedUsersTab);
friendsTabHFM.add(searchTab);

if(Constants.isGetConnectedFriends){
    Constants.isGetConnectedFriends =false ;
    if(friendsVFM.getFieldCount()!= 0){
        friendsVFM.deleteAll();
    }
    //GET CONNECTED FRIENDS WEB SERVICE CALL
    GetConnectedFriendsInterMediater getConnectedFriendsInterMediater = new GetConnectedFriendsInterMediater(WebServiceDetails.METHOD_GET_CONNECTED_USER, Jxa.loginUserName);
    PleaseWaitPopupScreen.showScreenAndWait(getConnectedFriendsInterMediater, Constants.PLEASE_WAIT_TEXT);

}else if(Constants.isGetUserByUsername){
    //Constants.isGetUserByUsername = false ;

    GetUserByUsernameIntermediator getUserListIntermediator=new GetUserByUsernameIntermediator(Jxa.loginUserName ,SearchUserScreen.userName);
    PleaseWaitPopupScreen.showScreenAndWait(getUserListIntermediator, Constants.PLEASE_WAIT_TEXT);

}else if(Constants.isGetAllUser){
    Constants.isGetAllUser = false ;

    GetAllUserListIntermediator getAllUserListIntermediator=new GetAllUserListIntermediator(WebServiceDetails.METHOD_FIND_USERS,SearchUserScreen._ageRange,SearchUserScreen._status,SearchUserScreen._religion,String.valueOf(SearchUserScreen._page) ,Jxa.loginUserName);
    PleaseWaitPopupScreen.showScreenAndWait(getAllUserListIntermediator, Constants.PLEASE_WAIT_TEXT);
}


if(_mainScreenVFM.getFieldCount()!=0){
    _mainScreenVFM.deleteAll();
}
_mainScreenVFM.add(friendsTabHFM);
_mainScreenVFM.add(friendsVFM);

这些代码用于一个选项卡,其中有两个子选项卡。对于子选项卡,它运行正常,但不适用于主选项卡。

还有一个场景,当调用 GetConnectedFriendsInterMediater 时,我在 friendsVFM 中添加了创建例外的列表。 代码是:

GetConnectedFriendsWebService getFriendsWebService = new GetConnectedFriendsWebService(method ,userName);
    Vector friendsVecList= getFriendsWebService.getFriends();

Constants.connectedUsersVector = friendsVecList ;

synchronized (UiApplication.getEventLock()) {
    if(TabControlScreen.friendsVFM.getFieldCount()!=0){
        TabControlScreen.friendsVFM.deleteAll();
    }
    TabControlScreen.friendsVFM.add(ConnectedFriends.getInstance(KingdomConnectMain.buddyList)); //HERE LIST IS ADDED
}

我已经解决了这个问题,当我切换标签时,我没有为 friendsVFM 创建新实例,并且使用了当时导致异常的相同实例。现在,相同的异常是当我尝试在 _listVFM 中添加 buddyList 时抛出。我知道这是由于再次添加 buddyList 已添加。有任何解决方案,以便我可以毫无例外地添加列表。代码:

//创建BUDDYLIST SCREEN的单一参考

public static ConnectedFriends getInstance(BuddyListField buddyListField){
        if(connectedFriends==null){
            connectedFriends = new ConnectedFriends(buddyListField);
        }
        return connectedFriends;
    }

public ConnectedFriends(BuddyListField buddyListField) {
        if(_listVFM!=null){
            _listVFM.deleteAll();
        }
        _listVFM = new VerticalFieldManager();

        _listVFM.add(buddyListField);//HERE IS EXCEPTION ,BUT WANT TO ADD THE LIST //SECOND TIME TOO
}

当我从另一个标签返回到sam标签时,它会抛出异常,换句话说我无法添加列表。

2 个答案:

答案 0 :(得分:1)

当您尝试按照Signare的建议添加两次字段时,会发生非法状态异常。我想你应该先试试这个: friendsVFM.getManager().delete(friendsVFM);

答案 1 :(得分:0)

我通过在buddyList上使用getManager()并删除它来解决它。再次按照要求添加它并且它工作。对此进行编码:

if(ConnectedFriends.getInstance(KingdomConnectMain.buddyList).getManager()!= null){
            ConnectedFriends.getInstance(KingdomConnectMain.buddyList).getManager().delete(ConnectedFriends.getInstance(KingdomConnectMain.buddyList));
            }
            TabControlScreen.friendsVFM.add(ConnectedFriends.getInstance(KingdomConnectMain.buddyList));

在代码的第二部分中调用 GetConnectedFriendsWebService 时使用此代码。