This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Spring and the fly likes How to avoid IndexOutOfBounds exception in this situation Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Frameworks » Spring
Reply Bookmark "How to avoid IndexOutOfBounds exception in this situation" Watch "How to avoid IndexOutOfBounds exception in this situation" New topic
Author

How to avoid IndexOutOfBounds exception in this situation

Jozo Stan
Greenhorn

Joined: Aug 18, 2012
Posts: 11
Hello everyone!


I have a database table with sport matches. In my application users can choose which matches they want to follow by clicking on add in a data-tables table. I fetch matches from database with this method:




With that method I achieve that only new matches are shown to the user. Finished matches remain in database. For example, if there are 10 matches. 4 are finished. Number of matches is still 10 but I fetch in my list only 6. When user wants to add a match with ID >=6, application crashes and the java.lang.IndexOutOfBoundsException appears. If I remove the WHERE part of query, then I don't receive this exception.


Here is my code:

Controller index.java




How could I solve this exception?

Thanks.
Jozo


Bill Gorder
Bartender

Joined: Mar 07, 2010
Posts: 1282

I would step through your code in a debugger. You are removing and adding to lists by index. Clearly the size of the lists your are getting back are not what you are expecting. There is an error in your logic.


[How To Ask Questions][Read before you PM me]
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: How to avoid IndexOutOfBounds exception in this situation
 
Similar Threads
Form for fetching data from database and displaying results on same page
@ModelAttribute behavior
ID isn't binded with form object
How to get and use the parameter from URL?
on submit, model object returning null