Olá pessoal,
Tenho um array list que pega valores do banco, segue abaixo a sintaxe que joga os valores pras TextsFields:
public void SelecionaDadosAlteracao() {
try {
listPatrimonios = new ArrayList<CMPatrimonios>();
CCPatrimonio controlePatrimonio = new CCPatrimonio();
int linhaControle = tableControlePatrimonios.getSelectedRow();
int linhaPesquisaControle = tablePesquisaPatrimonios.getSelectedRow();
if (linhaControle > 0) {
listPatrimonios= controlePatrimonio.ControleSelecionaDadosAlteracao(listPatrimonios.get(linhaControle).getCod()); //aqui se encontra o erro
for (int i =0; i < listPatrimonios.size(); i++) {
txtNomePatrimonio.setText(listPatrimonios.get(i).getNome());
txtNomenclaturaPatrimonio.setText(listPatrimonios.get(i).getNomenclatura());
cmbTipoPatrimonio.setSelectedItem(listPatrimonios.get(i).getTipo());
cmbSalaCadastrar.setSelectedItem(listPatrimonios.get(i).getSala());
}
}else if(linhaPesquisaControle > 0){
listPatrimonios= controlePatrimonio.ControleSelecionaDadosAlteracao(listPatrimonios.get(linhaPesquisaControle).getCod()); //Aqui se encontra o erro
for (int i =0; i < listPatrimonios.size(); i++) {
txtNomePatrimonio.setText(listPatrimonios.get(i).getNome());
txtNomenclaturaPatrimonio.setText(listPatrimonios.get(i).getNomenclatura());
cmbTipoPatrimonio.setSelectedItem(listPatrimonios.get(i).getTipo());
cmbSalaCadastrar.setSelectedItem(listPatrimonios.get(i).getSala());
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
erro:
java.lang.IndexOutOfBoundsException: Index: 1, Size: 0
at java.util.ArrayList.RangeCheck(Unknown Source)
at java.util.ArrayList.get(Unknown Source)
at view.CFGerenciarPatrimonios.SelecionaDadosAlteracao(CFGerenciarPatrimonios.java:892)
at view.CFGerenciarPatrimonios$8.actionPerformed(CFGerenciarPatrimonios.java:439)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
se alguem puder me ajudar, fico grato.
att, Paulo Mello