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.

Edited 5 Years Ago by localp: n/a

not urgent.

Might not be for you. If you don't know the answer, just keep quite without being a Bonehead .

And sorry if i was rude !

Comments
sorry if i was rude
troll

Does the Fruit class extend Food?

No it doesn't extend. Food Class is a bean class

public class Food{

int foodId;
String foodName;
Fruit f;

}

----

//Fruit.java

Public class Fruit {

int fruit_id;
String fruit_name;
}

And i have a List<Food> food, This contains all of the above mentioned attributes. I need to save the 'Fruit' attributes to a List<Fruit> f object.

Not replying within 30 mins doesn't mean that it's not urgent. i didn't get the mail to my inbox. and i randomly checked the site to find your reply. Thanks

OK, that's weird, but I guess you have your reasons.

Fruit is an Object. It is being saved into the 'List<Food> item' .

will not work if Fruit isn't a subclass of Food

It's impossible to diagnose any more from these isolated fragments of code and an error message with no line number. Can you post all the code with the full error message including the class/line number?

Edited 5 Years Ago by JamesCherrill: n/a

Might not be for you. If you don't know the answer, just keep quite without being a Bonehead .

And sorry if i was rude !

actually, I do know the answer. Or would if I were to bother with homework kiddos like you who think themselves so important they can decide their problems are so important I should drop everything and help them ASAP for no reward except getting bitched at for it not being exactly what they had in mind.

actually, I do know the answer. Or would if I were to bother with homework kiddos like you who think themselves so important they can decide their problems are so important I should drop everything and help them ASAP for no reward except getting bitched at for it not being exactly what they had in mind.

I didn't ask anyone to drop their work and help. Try to undestand what i have written before commenting.

PS: Admin of Daniweb, please include a section with tips on how to undestand a question. i see some people finding it difficult to do so and ending up being a clown within the community.

Thank You

This question has already been answered. Start a new discussion instead.