This action of a button is to add the path of a file to a JList
:
private void bArquivoActionPerformed(java.awt.event.ActionEvent evt) {
JFileChooser fileChooser = new JFileChooser();
fileChooser.showOpenDialog(this);
File arquivo = fileChooser.getSelectedFile();
listaarquivos.add(arquivo);
tArquivo.setText(arquivo.getPath());
DefaultListModel modelo = new DefaultListModel();
tListaArquivo.setModel(modelo);
String l = arquivo.getPath();
if(listaarquivos.size()==1){
modelo.add(0,l);
index = 1;
}else{
modelo.add(index, l);
index++;
}
}
It shows the following error when the button is called the second time and so it goes to else
:
Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 1 > 0