Buonasera gente,
mi sono un pò bloccato.
Un programma mi dà errore
L'errore avviene così:
apro un JFrame con il JTable in questione, seleziono una riga, poi chiudo il JFrame manualmente;
quando riapro il JFrame mi da questo errore.
Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: -1
at java.util.Vector.elementData(Vector.java:734)
at java.util.Vector.elementAt(Vector.java:477)
at Gestionale$53.valueChanged(Gestionale.java:5118)
at javax.swing.DefaultListSelectionModel.fireValueChanged(DefaultListSelectionModel.java:184)
at javax.swing.DefaultListSelectionModel.fireValueChanged(DefaultListSelectionModel.java:164)
at javax.swing.DefaultListSelectionModel.fireValueChanged(DefaultListSelectionModel.java:211)
at javax.swing.DefaultListSelectionModel.changeSelection(DefaultListSelectionModel.java:405)
at javax.swing.DefaultListSelectionModel.changeSelection(DefaultListSelectionModel.java:415)
at javax.swing.DefaultListSelectionModel.removeSelectionIntervalImpl(DefaultListSelectionModel.java:576)
at javax.swing.DefaultListSelectionModel.clearSelection(DefaultListSelectionModel.java:420)
e un sacco di altre cose.
vi posto il listener dove mi dà errore (alla riga con : obj=model.getDataVector().elementAt(h); )
table_cf_interna.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
DefaultTableModel model;
Object obj=null;
@Override
public void valueChanged(ListSelectionEvent e) {
model=(DefaultTableModel)table_cf_interna.getModel();
/*ottengo il codice dell'impresa*/
int h=table_cf_interna.getSelectedRow();
/*-----------------QUI MI DA ERRORE--------------------*/
obj=model.getDataVector().elementAt(h);
/*---------------------------------------------*/
System.out.println(obj.toString());
String[] asd=obj.toString().split(", ");
int codasd=Integer.parseInt(asd[1]);
/*----*/
int riga=table_cf_interna.getSelectedRow();
lbl_cod_cliente.setText(String.valueOf(codasd));
Connection con1=null;
Statement stat1=null,stat3=null;
ResultSet r3,r4;
Impresa impresaSelezionate=null;
try{
org.sqlite.SQLiteConfig config = new org.sqlite.SQLiteConfig();
config.enforceForeignKeys(true);
con1=DriverManager.getConnection(sqlite,config.toProperties());
stat1=con1.createStatement();
stat3=con1.createStatement();
r3=stat1.executeQuery(""
+ "SELECT * "
+ "FROM imprese "
+ "WHERE cod='"+codasd+"' "
+ "");
while(r3.next()){
//ecc. ecc..
Si capisce?