Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4624576
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T03:08:56+00:00 2026-05-22T03:08:56+00:00

I am trying to design a model in which I have a List of

  • 0

I am trying to design a model in which I have a List of List of child object having same super class. This model will be a Model of a ListView. The super class is:

public class Element implements Serializable {

    private static final long serialVersionUID = 10121L;
    
    private String value;

    public Element(String value) {
        this.value = value;
    }

    public String getValue() {
        return value;
    }

    public void setValue(String value) {
        this.value = value;
    }

    @Override
    public String toString() {
        return "Element [value=" + value + "]";
    }   
}

One of the sub class is:

public class DateElement extends Element {

    private static final long serialVersionUID = 10122L;

    private DateTime date;
    
    public DateElement(String value, DateTime date) {
        super(value);
        this.date = date;
    }

    public DateTime getDate() {
        return date;
    }

    public void setDate(DateTime date) {
        this.date = date;
    }

    @Override
    public String toString() {
        return "DateElement [date=" + date + ", value=" + getValue() + "]";
    }   
}

I am instantiating the List of List as:

this.userMonitorMap = new ArrayList<List<? extends Element>>(0);

Adding a List of DateElement in userMonitorMap as:

List<DateElement> dateElements = getDateElements();
userMonitorMap.add(dateElements);

Upto this portion I am having no trouble. But the population of the ListView has problem, the code snippet is:

        ListView row = new ListView("row", userMonitorMap) {
            
            @Override
            protected void populateItem(ListItem rowItem) {
                List<? extends Element> columnMap = (List<? extends Element>) rowItem;
                ListView column = new ListView("column", columnMap) {
                    
                    @Override
                    protected void populateItem(ListItem columnItem) {
                        Element element = (Element) columnItem; //The compile time error is here
                    }
                };
                rowItem.add(column);
            }
        };

I have commented the problem in my code. How can I achieve this? What are the changes do I need?

The eclipse IDE red marked that line and the error message is: Cannot cast from ListItem to Element

Thanks and Regards.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T03:08:57+00:00Added an answer on May 22, 2026 at 3:08 am

    The ListItem isn’t the object in the list itself, it contains a model which contains your object. You should be using:

    Model<Element> elementModel = columnItem.getModel();
    

    or

    Element element = columnItem.getModelObject();
    

    Take a look at these examples

    Your code should read:

    ListView row = new ListView(“row”, userMonitorMap) {

            @Override
            protected void populateItem(ListItem rowItem) {
                List<? extends Element> columnMap = rowItem.getModelObject();
                ListView column = new ListView("column", columnMap) {
    
                    @Override
                    protected void populateItem(ListItem columnItem) {
                        Element element = columnItem.getModelObject();
                    }
                };
                rowItem.add(column);
            }
        };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to design a tagging system with a model like this: Tag:
I have a Java project that I'm trying to implement with a model-view-controller design.
I am trying to design my Class Diagram. But I get stuck on this
I am trying to design a data model which can hold a very large
I am trying to design an entity model using JPA2.0 via hibernate. I have
I'm trying to design a data model for my current project, and I'm having
I am trying to design an object model (for C#), and can't work out
I have an application which I am trying to design using the MVVM pattern.
I have been trying different techniques while designing this application, which to me is
I am trying to design model associations in rails that consist of the following

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.