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.

not urgent.

commented: Agreed, not urgent, and -ve rep cancellation FTW +17

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 !

commented: troll -3
commented: sorry if i was rude -3

Does the Fruit class extend Food?

(30 minutes later) ... no answer. Obviously not urgent after all.

commented: indeed +15
commented: LOL +17
commented: :) +13

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?

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.