I have a List
List<Food> item
, which holds the following.
'Food foodID', 'Food foodName', 'Fruit fruit'
Fruit is an Object. It is being saved into the 'List<Food> item' .
Now i need to create an Object of 'Fruit' , and save all the 'Fruit' elements in the 'List<Food> item' object to newly created 'Fruit' object. How do i program this ?
I did the following but i am getting an error
javax.faces.el.EvaluationException: java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to com.ert.num.data.Food
My code is ;
List<Food> d = get_Food(); // this is where all the Food elements gets saved
for (int i=0; i< d.size(); i++)
{
setFruit( d.get(i).getFruitProfile());
}
The code fragment for the 'getFruitProfile()' method as follows; By calling this method, it would take all the 'Fruit' objects from the 'List<Food> d' and save it to 'setFruit()'.
public Fruit getFruitProfile() {
return fruitProfile;
}
Please help. I am helpless here.