1

I have 3 classes representing 3 differents things: Article, Photos, and Videos

All 3 things have 2 properties in common: A title and and image.

I have an interface called ImageTitleListItem that the 3 classes implement. That interface is just a getter/setter for title and image

I have 3 classes that are ArrayList:

Articles extends ArrayList<Article>
Photos extends ArrayList<Photo>
Videos extends ArrayList<Video>

I have an ArrayListAdapter that display a list of those images with there title.

The constructor of the ArrayListAdapter receive ArrayList<ImageTitleListItem> as a parameter

When I call it :

adapter = new ArrayListAdapter(Articles)

I have an error:

The constructor ArrayListAdapter(Articles) is undefined

That's normal, so i tried to cast it:

adapter = new ArrayListAdapter((ArrayList<ImageTitleListItem>)Articles)

Now the error is:

Cannot cast from Articles to ArrayList<ImageTitleListItem>

I'm relativly new to java so there's a trick I'm missing, can somebody help me on this.

Thanks

1
  • Post your constructor and relevant parts of your code as a SSCCE: sscce.org Commented May 27, 2013 at 13:16

1 Answer 1

3

The ArrayListAdapter constructor needs to be defined as

 ArrayListAdapter(List<? extends ImageTitleListItem> list)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.