As the title says, I have a problem when trying to modify an attribute of an object at the time of being traversed; what I do is create a cycle to go through a list, within this cycle I create an object which I will fill from a SQLite database, and when I modify one of the attributes I get an error of NullPointerException, the funny thing is that the error comes out after having already done a cycle, and if I do not modify the object the objects fill up well.
selected = "0"+String.valueOf(i+1);
Log.e("onItemSelected",selected);
aList = sqLiteAccumulated.getAllAccumulated(selected);
sqLiteItems = new SQLiteItems(ItemActivity.this);
pList = new ArrayList<ProductModel>();
Log.e("aList size", aList.size()+"");
for (int j = 0; j<aList.size(); j++){
productModel = new ProductModel();
productModel = sqLiteItems.readItem(aList.get(j).getMI2_ARTIC());
productModel.setMI_ACT(Float.parseFloat(aList.get(i).getMI2_ACT()));
if (productModel!=null){
pList.add(productModel);
}
}
and the log shows me this
java.lang.NullPointerException: Attempt to invoke virtual method 'void co.dibso.gomezvelasquezvendedores.Modelo.ProductModel.setMI_ACT(float)' on a null object reference
but this happens after having already gone through a cycle.