Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Deleting The Whole Table problem(Index Out Of Bounds)

 
michael johanson
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


the compiler throws me an index out of bounds, i cant find the reason why im getting this, so I tried to remove piece by piece the whole code, until I ended up in this..
but still I cant solve this problem..

when I select all the rows in the Table and press the delete button, it deletes 99% of it, and there is one remains, and an IndexOutOfBoundsException throws me, help with this please
 
Rob Spoor
Sheriff
Pie
Posts: 20495
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1) Don't use getSelectedRow(); use the real rows that are selected.

2) If you remove a row, all later rows will have their indexes decreased by one. You can prevent this by iterating backwards:
This code does assume that selectedRows will be sorted. If you want to make sure, call Arrays.sort before you start iterating.
 
michael johanson
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you so much!

learned again!
 
Maneesh Godbole
Saloon Keeper
Posts: 11021
12
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"mykel java"

Please check your private messages for an important administrative matter
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic