This week's book giveaway is in the JavaFX forum.
We're giving away four copies of Introducing JavaFX 8 Programming and have Herbert Schildt on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Generic error! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Introducing JavaFX 8 Programming this week in the JavaFX forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Generic error!" Watch "Generic error!" New topic

Generic error!

Robert Bonslater

Joined: Jan 30, 2005
Posts: 28
When I compile my code it produces:

jakarta-tomcat-5\webapps\begjsp-tourism\WEB-INF\classes\com\wrox\tourism\db\Even warning: [unchecked] unchecked call to add(E) as a member of the
raw type java.util.ArrayList
I thought I defined the gerneric types. What do I need to do to list.add(new Attraction(attraction));?
Here is the piece of code:

public Collection findAll() {

PreparedStatement ps = null;
ResultSet rs = null;
ArrayList list = new ArrayList();

String sql = "SELECT * from attraction ";

try {

if (con.isClosed()) {
throw new IllegalStateException("error.unexpected");

ps = con.prepareStatement(sql);
rs = ps.executeQuery();

while( {

Attraction attraction = new Attraction();

list.add(new Attraction(attraction));


return list;
K Riaz
Ranch Hand

Joined: Jan 08, 2005
Posts: 375
Try changing list.add(new Attraction(attraction)) to list.add(attraction)
Robert Bonslater

Joined: Jan 30, 2005
Posts: 28
Right, I also needed to use <Type_Name> tags after the array:

ArrayList<Attraction> list = new ArrayList<Attraction>();

Liam Tiarnach
Ranch Hand

Joined: Aug 06, 2004
Posts: 51
I don't see any "generics" in your code...
The error state that you are using a raw non parameterized ArrayList...
If you want a generified ArrayList, then you have to include the generic parameters ( terminology anyone ? )...

now the ArrayList is set to take only Attraction types...

here is a link to Sun's Java Tutorial Generics Lesson...

check it out so that you can learn what and how to use generics...

have fun...

- Liam...<br />- ' He who never sleeps... '
I agree. Here's the link:
subject: Generic error!
It's not a secret anymore!