IllegalStateException when adding a field manager in another manager

I am trying to add a list to the VerticalFieldManager , and then this manager to another VerticalFieldManager . I use it in custom tabs. The first time the application starts, it works fine, but when I switch to another tab and return to it, it gives IllegalStateException .

I tried this in many ways, but did not get what throws an exception when adding a VerticalFieldManager.

I am using the code:

//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); 

This code is for a tab that has two sub tabs. For sub-tabs, it works fine, but not for the main tab.

There is another scenario where GetConnectedFriendsInterMediater is called in which I add a list to friendsVFM that throws an exception. Code for this:

 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 } 

I solved the problem when I switched the tab, I did not create a new instance for friendsVFM and used the same instance that was throwing an exception at the time. Now this is the same exception when I try to add a buddyList to _listVFM . I know this has to do with adding buddyList again, which has already been added. Is there any solution so that I can add a list without exception. Code for this:

// CREATE A SINGLE BUDDYLIST SCREEN GUIDE

 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 } 

When I return from another tab to the sam tab, it throws an exception or, in other words, I cannot add a list.

+4
source share
2 answers

I solved this with getManager () on a buddyList and removed this. Once again I added it as required, and it worked. Code for this:

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

This code is used when calling GetConnectedFriendsWebService in the second part of the codes.

+1
source

Illegal state exception occurs when you try to add fields twice, as suggested by Signare. I think you should try this first: friendsVFM.getManager().delete(friendsVFM);

+1
source

Source: https://habr.com/ru/post/1484201/


All Articles