0
I have a ArrayList
that should be receiving numbers from 0 to 15, within a for
, however it seems that is getting recorded in all indexes the last value 15.
ArrayList <PaginaPrincipalSO> FilaTPSO= new ArrayList();
PaginaPrincipalSO TPSO = new PaginaPrincipalSO();
public void armazenarTPSO(PaginaPrincipalSO a){
FilaTPSO.add(a);
}
public void preencherTPSO(){
int NPF = retornaNPF();
JOptionPane.showMessageDialog(null, NPF); //apenas para confirmar o valor de NPF que chega como 15
for(int y=0;y<=NPF;y++){
TPSO.setNPF(y);
armazenarTPSO(TPSO);
}
for(int y=0;y<=NPF;y++){
JOptionPane.showMessageDialog(null, FilaTPSO.get(y).getNPF()); //buscando os valores dentro do arraylist e recebendo como retorno sempre 15
}
}
I’m not seeing any problems. Is it somewhere in the code that you’re not showing? You’re creating 16 elements in the array?
– Maniero
The problem is that it always adds the same object, rather than instantiating one at each iteration.
– Wakim
this, are 16 elements. I am just putting here, because it does not seem to have errors and this part of the code is independent of the others at first. But when I spin the last I always get 15.
– Rodrigo Segatto
You think you would have to do this every time: Paginaprincipalso TPSO = new Paginaprincipalso();
– Rodrigo Segatto
CORRETO @Wakin. It worked... As I appreciate your reply, since it was a comment?
– Rodrigo Segatto
@Wakim good, I ate ball in this.
– Maniero