File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Unable to delete a list entry at runtime

 
Mansoor Khan
Greenhorn
Posts: 17
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a list which consists of names and a button to delete the selected name when clicked. The names in the list are read from a database. When I click on the button to delete the selected entry, I get an error like this on the terminal window and the entry is not deleted:

Error : java.lang.ArrayIndexOutOfBoundsException: Array index out of range: 3


The code for the same is as below :


The bug may be evident but I am not able to fix it. Kindly help me get over with this.
 
Rob Camick
Ranch Hand
Posts: 2473
8
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Read the JList API and follow the link to the Swing tutorial on "How to Use Lists' for a working example that dynamically adds/removes items from a JList.
 
Mansoor Khan
Greenhorn
Posts: 17
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I did that. Can you please help me find where I am wrong in my code?
 
Darryl Burke
Bartender
Posts: 5115
11
Java Netbeans IDE Opera
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mansoor Khan wrote:I did that. Can you please help me find where I am wrong in my code?

Not without an SSCCE.
 
Peter Taucher
Ranch Hand
Posts: 174
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'd recommend using the ListModel for adding / removing of items (like in the swing tutorials). Here's a working mini-example:

 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic