• Post Reply Bookmark Topic Watch Topic
  • New Topic

JList help needed

 
Robert Upshall
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have an application that read from a data base and displays the results in a JList.
The read works fine, my problem occurs when I try to delete an item from the list and the database.
I have tried to approach this in 2 way, both give different exceptions, the first approach was to first delete the record from the DB, then load a vector with the records from the DB, the do JList.setListData(JList), the exception i get here is an array index out of bounds error on the setListData method.
The second approach I tried was to first remove the record from the data base first, the do JList.remove(selectedIndex), this causes a null pointer exception.
I have no idea what I am doing wrong or how to work around this, any help woruld be greatly appreciated.
Robert
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could we see your code? The second approach sounds pretty solid and worry free, but if I could see the code you are using to do it, that would help debug.
 
Robert Upshall
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
/**
* Comment
*/
public void deleteButton_ActionPerformed(
java.awt.event.ActionEvent actionEvent)
{
try
{
String initials =
((String) getSession().get(EnterInitials.INITIALS)).trim().toUpperCase();
int i = getPaymentList().getSelectedIndex();
Object[] entmstKey = new Object[1];
entmstKey[0] = (BigDecimal) ((Object[]) getPaymentVector().elementAt(i))[0];
DB2File entmst =
new DB2File(
getSystem(),
"/QSYS.LIB/%LIBL%.LIB/ENT" + initials + ".FILE/%FILE%.MBR",
DB2File.KEYED,
entmstKey);
entmst.open(AS400File.READ_WRITE);
Record record = entmst.chain();
if (record != null)
{
entmst.delete();
}
entmst.close();
getPaymentList().delete(i);
}
catch (Exception e)
{
PSAOptionPane.showErrorDialog(this, e);
}
return;
}
 
Robert Upshall
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I found my problem, it was caused in a completely different place because of the list refresh.
The bean was throwing the event and it was being caught in another place I wasn't expecting, this was where the problem was.
Its fixed now, sorry to bother,
Robert
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!