state manager - index out of bounds exception

rleiman

Well-Known Member
Licensed User
Longtime User
Hi Everyone,

I'm using the state manager in an app and just added 2 additional edit text boxes. When I run the app I get the error shown in the attachment.

Thanks.
 

Attachments

  • state manager error.jpg
    33.5 KB · Views: 273

rleiman

Well-Known Member
Licensed User
Longtime User
Temporary Work-Around

I was able to perform a work-around to the issue.

I believe it has something to do with when the state manager restores the state because of this senario.

Let's say we have 5 edit text boxes on the activity. The user exists from the activity and this code is run:

B4X:
Sub Activity_Pause (UserClosed As Boolean)

    ' Save the state of the activity so everything can be re-displayed when the user comes back to this activity.
    '------------------------------------------------------------------------------------------------------------
    StateManager.SaveState(Activity, "People")
    StateManager.SaveSettings
End Sub

At this point 5 edit text boxes are saved and I exit the app.

Now I add 2 more edit text boxes which makes 7 of them now.

When the activity is called again after starting the app you get the error because no information is saved for 7 edit text boxes because of the 2 new ones.

B4X:
Sub Activity_Resume

    PopulateTheListView

    ' Restore the state this activity was in prior to exiting it.
    '------------------------------------------------------------
    StateManager.RestoreState(Activity, "People", 0)
End Sub

The work-around for now is whenever you add more views like the edit text boxes is to comment out the StateManager.RestoreState line run the app and go into the activity with the new views and exit the app using the back or home button. Next un-comment the StateManager.RestoreState line and run the app going back into that same activity and the error will not happen.

Erel, can you add code in the state manager to look and handle this scenario?

Thanks.
 
Last edited:
Upvote 0

warwound

Expert
Licensed User
Longtime User
Hi.

I was just about to report the same bug but found this thread so i'll post here.

I'm getting an index out of bounds error using StateManager when i add or remove Views from a layout that has had it's state saved.

It's not a massive problem - just a 'development' problem while i'm updating layouts.

But i'd like to see StateManager updated to handle such basic errors if possible?

By the way i'm very impressed with StateManager - it's an instant solution to a rather common problem and works very well.

Martin.
 
Upvote 0

rleiman

Well-Known Member
Licensed User
Longtime User
Maybe Erel will have that one working in the next release.

It's the best product for developing Android app I've seen.

 
Upvote 0

warwound

Expert
Licensed User
Longtime User
Hi.

My application pauses at line 184 in StateMananger:

B4X:
Sub getNextItem(list1 As List) As Object()
   listPosition = listPosition + 1
   Return list1.Get(listPosition) ' line 184
End Sub

When i click continue in the B4A IDE, the application continues with this exception reported in the Log:

Error loading state.
java.lang.IndexOutOfBoundsException: Invalid index 12, size is 12

It's no great problem as it only occurs (for me) when developing and updating a layout.

My only solution is to uninstall the old version of the application then install the newer version - that clears the saved state file.

But thinking - maybe i could go through Settings > Applications > Manage Applications.
Would clearing the application cache and saved data here also clear the saved state file?

Martin.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…