Results 1 to 2 of 2
- 03-23-2011, 04:59 AM #1
Member
- Join Date
- Mar 2011
- Posts
- 1
- Rep Power
- 0
ArrayList - "Unchecked or unsafe operations" at compile
I have written the following program using an ArrayList.
When I try to compile, I have "unchecked or unsafe operations." I compiled it with the suggested -Xlint:unchecked parameter, and there are 11 errors: on all of the <ArrayList>.add(<item>).Does anyone know what I need to change, or what I'm doing wrong?Java Code:import java.util.ArrayList; public class TestArrayList { public static void main(String[] args) { //create a list to store cities ArrayList cityList = new ArrayList(); //add some cities to the list cityList.add("London"); //citylist now contains [London] cityList.add("Denver"); cityList.add("Paris"); cityList.add("Timbuktu"); cityList.add("Burlington"); cityList.add("Dublin"); cityList.add("Miami"); cityList.add("Tokyo"); //cityList now contains[London,Denver,Paris,Timbuktu,Burlington, Dublin,Miami,Tokyo] System.out.println("list size " + cityList.size()); System.out.println("is miami in the list? " + cityList.contains("Miami")); System.out.println("location of denver in the list " + cityList.indexOf("Denver")); System.out.println("Is the list empty " + cityList.isEmpty()); //insert new city at index 2 cityList.add(2, "Xian"); //remove a city from the list cityList.remove("Miami"); //remove city at index 1 cityList.remove(1); //display contents in the list System.out.println(cityList.toString()); //display contents in reverse order for (int i = 0; i < cityList.size(); i++) { System.out.println(cityList.get(i) + " "); } //create a list to store two circle ArrayList list = new ArrayList(); //add two circles list.add(new Circle4(2)); list.add(new Circle4(3)); //display area of first circle in list System.out.println("\nthe area of the circle? " + ((Circle4)list.get(0)).getArea()); } }
Thanks
-
Look at the messages carefully -- they're warnings, not errors, and that's a big difference. They're warning you that you're not using generics with your ArrayList, and if you don't need to use generics, you can ignore them.
In the future, you'll want to post your entire error messages here rather than paraphrasing them so we will have no doubt as to your exact error message.
Similar Threads
-
Unchecked or Unsafe Operations Error Message
By littleone in forum New To JavaReplies: 9Last Post: 01-31-2011, 01:50 PM -
unchecked or unsafe operations-Recompile with -Xlint
By pronetin in forum Advanced JavaReplies: 15Last Post: 05-31-2010, 05:41 PM -
Unchecked or unsafe operations warning
By sky in forum New To JavaReplies: 3Last Post: 12-06-2009, 03:41 AM -
HashMapTest.java uses unchecked or unsafe operations.
By jeer in forum New To JavaReplies: 22Last Post: 05-08-2008, 12:00 PM -
Uses unchecked or unsafe operations message
By Robbinz in forum New To JavaReplies: 2Last Post: 12-06-2007, 10:56 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks