Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

How to avoid IndexOutOfBounds exception in this situation

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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


 
Bartender
Posts: 1682
7
Android Mac OS X IntelliJ IDE Spring Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
No one can make you feel inferior without your consent - Eleanor Roosevelt. tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic