aspose file tools*
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 Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Generic error!" Watch "Generic error!" New topic
Author

Generic error!

Robert Bonslater
Greenhorn

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
tDAO.java:217: warning: [unchecked] unchecked call to add(E) as a member of the
raw type java.util.ArrayList
list.add(event);
^
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(rs.next()) {

Attraction attraction = new Attraction();
attraction.setUserId(rs.getString(1));
attraction.setPassword(rs.getString(2));
attraction.setName(rs.getString(3));
attraction.setDescription(rs.getString(4));
attraction.setWebSite(rs.getString(5));
attraction.setAddress(rs.getString(6));

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
Greenhorn

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

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

Thanks
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...
http://java.sun.com/docs/books/tutorial/extra/generics/index.html

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: http://aspose.com/file-tools
 
subject: Generic error!
 
Similar Threads
JDBC Code Optimization Question
On small stress getting Exhausted Resultset
Fill java.awt.Choice from a List generated by a resultSet
passing parameters using Prepared Statement
inserting BLOB values using prepared statement