1
I need to put in a array
of double
the quantity field data coming from the database. By doing this with the following code:
static List<Historico> listaComCincoUltimosMeses = new ArrayList<Historico>
();
static double[] arrayinvertidoComUltimosCincoMeses = new double[listaComCincoUltimosMeses.size()];
int k = 0;
for (Historico hist : listaComCincoUltimosMeses) {
System.out.println(hist.getMesesHistoricos() == null ? "Erro" :
hist.getMesesHistoricos());
System.out.println(hist.getQuantidade());
arrayinvertidoComUltimosCincoMeses[k] = hist.getQuantidade();
System.out.println(arrayinvertidoComUltimosCincoMeses.length);
System.out.println("Array"+ arrayinvertidoComUltimosCincoMeses[k]);
k++;
}
I get the following error:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
Does anyone know why?
I want to put in a double array because I get the array as input in a function.
public static double fatorAmortecimentoExponencial(double... d) {
...
}
your array is instantiated and has this position?
– Aline
Where and how the
arrayinvertidoComUltimosCincoMeses
?– Victor Stafusa
Related question (not duplicate): https://answall.com/q/203324/132
– Victor Stafusa