The classcastexception happens on retrieving the N-th item from the
list. The class cast tries to cast the model object of the listview to
a List. Apparently the argument to the listview is not a List, but
somethign that returns a QuestionAndAnswer.
Are you looking at the correct ListView (i.e. are there more ListView
s on your page)?
Martijn
On Thu, Oct 23, 2008 at 11:55 AM, Dipu <[EMAIL PROTECTED]> wrote:
> pass , sorry i have no clue
>
> On Thu, Oct 23, 2008 at 10:37 AM, pieter claassen <[EMAIL PROTECTED]>wrote:
>
>> Ok, I added;
>>
>> public class Debug {
>> public static void debug(List list) {
>> for (Object item : list) {
>> System.out.println("++DEBUG++: " +
>> item.getClass().toString());
>> }
>> }
>>
>>
>> and called debug just before I returned my ArrayList of question:
>>
>> public ArrayList<QuestionAndAnswer> getQuestions() {
>> Debug.debug(questions);
>> return questions;
>> }
>>
>> This is what I saw in my console. There are two objects in the list and
>> they are both QuestionAndAnswer objects
>>
>>
>> ++DEBUG++: class com.musmato.model.QuestionAndAnswer
>> ++DEBUG++: class com.musmato.model.QuestionAndAnswer
>>
>> Regards,
>> Pieter
>>
>>
>> On Oct 23, 2008, at 11:18 AM, Dipu wrote:
>>
>> can't you check what exactly is being returned by template.getQuestions()
>>> and if its a list what are the items in it
>>>
>>>
>>>
>>>
>>> On Thu, Oct 23, 2008 at 10:10 AM, pieter claassen <[EMAIL PROTECTED]
>>> >wrote:
>>>
>>> Hi Dipu,
>>>>
>>>> I tried that but when I do the following:
>>>>
>>>> protected void populateItem(ListItem item) {
>>>> System.out.println("+++++++" +
>>>> item.getModelObject().getClass().getName());
>>>> final QuestionAndAnswer qanda = (QuestionAndAnswer)
>>>> item.getModelObject();
>>>>
>>>> I find that I now get the ClassCastException in the System.out.println
>>>> line. It is clear as mud that the problem is that I am trying to force
>>>> something into a list which is not a list?
>>>>
>>>> Regards,
>>>> Pieter
>>>>
>>>>
>>>>
>>>> On Oct 23, 2008, at 10:59 AM, Dipu wrote:
>>>>
>>>> looks like template.getQuestions() is returning a list with items in it
>>>>
>>>>> which is not of the type QuestionAndAnswer
>>>>>
>>>>> try iterating through the list and logging the class name of each item
>>>>> in
>>>>> it
>>>>>
>>>>> Dipu
>>>>>
>>>>>
>>>>>
>>>>> On Thu, Oct 23, 2008 at 9:46 AM, pieter claassen <[EMAIL PROTECTED]
>>>>>
>>>>>> wrote:
>>>>>>
>>>>>
>>>>> I am getting a classcast exception in ListView that is stumping me.
>>>>>
>>>>>>
>>>>>> This is the error message (top few lines)
>>>>>>
>>>>>> WicketMessage: Error attaching this container for rendering:
>>>>>> [MarkupContainer [Component id = questioneditform]]
>>>>>>
>>>>>> Root cause:
>>>>>>
>>>>>> java.lang.ClassCastException: com.musmato.model.QuestionAndAnswer
>>>>>> at
>>>>>>
>>>>>>
>>>>>> org.apache.wicket.markup.html.list.ListItemModel.getObject(ListItemModel.java:55)
>>>>>> at org.apache.wicket.Component.getModelObject(Component.java:1558)
>>>>>> at
>>>>>>
>>>>>>
>>>>>> com.musmato.wicket.pages.templates.TemplateEditPage$QuestionEditForm$1.populateItem(TemplateEditPage.java:93)
>>>>>>
>>>>>>
>>>>>> This is the code that generates my ListItems:
>>>>>>
>>>>>> ListView questions = new ListView("questions",
>>>>>> template
>>>>>> .getQuestions()) {
>>>>>>
>>>>>>
>>>>>> @Override
>>>>>> protected void populateItem(ListItem item) {
>>>>>> final QuestionAndAnswer qanda =
>>>>>> (QuestionAndAnswer) item
>>>>>> .getModelObject();
>>>>>> setModel(new
>>>>>> CompoundPropertyModel(qanda));
>>>>>>
>>>>>>
>>>>>>
>>>>>> I know for a fact that template.getQuestions() produces an ArrayList.
>>>>>>
>>>>>> The arraylist works when there is only 1 item in it but when I have
>>>>>> more
>>>>>> than 1 item, it fails with the ClassCastException. Is this a wicket
>>>>>> problem
>>>>>> or am I doing something wrong?
>>>>>>
>>>>>> Regards,
>>>>>> Pieter
>>>>>> pieter claassen
>>>>>> [EMAIL PROTECTED]
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>> ---------------------------------------------------------------------
>>>>>> To unsubscribe, e-mail: [EMAIL PROTECTED]
>>>>>> For additional commands, e-mail: [EMAIL PROTECTED]
>>>>>>
>>>>>>
>>>>>>
>>>>>> pieter claassen
>>>> [EMAIL PROTECTED]
>>>>
>>>>
>>>>
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: [EMAIL PROTECTED]
>>>> For additional commands, e-mail: [EMAIL PROTECTED]
>>>>
>>>>
>>>>
>> pieter claassen
>> [EMAIL PROTECTED]
>>
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [EMAIL PROTECTED]
>> For additional commands, e-mail: [EMAIL PROTECTED]
>>
>>
>
--
Become a Wicket expert, learn from the best: http://wicketinaction.com
Apache Wicket 1.3.4 is released
Get it now: http://www.apache.org/dyn/closer.cgi/wicket/1.3.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]