Results 1 to 6 of 6
  1. #1
    kbud123 is offline Member
    Join Date
    May 2011
    Posts
    3
    Rep Power
    0

    Default Help with some errors in my program

    I'm a new java student (currently in computer programming 101) I'm getting an error I've never seen before with this program...


    import java.util.ArrayList;
    public class Thirteen
    {
    public static void main (String[] args)
    {
    ArrayList nameList = new ArrayList();
    nameList.add("James");
    nameList.add("Catherine");
    nameList.add("Bill");

    for (int index = 0; index < nameList.size(); index++)
    {
    System.out.println("Index: " + index + "Name: " + nameList.get(index));
    }
    nameList.add(1, "Mary");

    System.out.println("After the changes, " + "here are the items now:");

    for (int index = 0; index < nameList.size(); index++)
    {
    System.out.println("Index: " + index + " Name: " + nameList.get(index));
    }}}



    I'm getting the error:

    Note: Thirteen.java uses unchecked or unsafe operations.
    Note: Recompile with -Xlint:unchecked for details.

    can someone please explain this to me ... thank you

    Sorry if this is in the wrong topic

  2. #2
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    That's not an error, it's a warning. If you wanna read the details google "java generics tutorial", short story, when you declare the array list do it like this
    Java Code:
    ArrayList<String> varName = new ArrayList<String>();
    Notice the added parameter in between <>, this specifies the type the array list will hold.

  3. #3
    kbud123 is offline Member
    Join Date
    May 2011
    Posts
    3
    Rep Power
    0

    Default

    thanks a bunch.. quick response too :) !

  4. #4
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    You are welcome, glad to have helped. Please mark your thread solved with the thread tools at the top.

  5. #5
    kbud123 is offline Member
    Join Date
    May 2011
    Posts
    3
    Rep Power
    0

    Default

    one more thing if you dont mind...

    ArrayList<String> varName = new ArrayList<String>();

    what do i replace string with if i want to use an array of integers?

  6. #6
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    You can't use primitives for the type, you can however; use the wrapper class which has similar names to the primitive type. int would be Integer, double is Double, etc. Lookup autoboxing for more details.

Similar Threads

  1. Replies: 4
    Last Post: 01-04-2011, 01:36 AM
  2. Errors with simple program... PLEASE HELP ME!!!
    By maxpower1000sa in forum New To Java
    Replies: 6
    Last Post: 05-04-2009, 12:55 AM
  3. Errors in Program (Right Triangle)
    By SupaStudy in forum New To Java
    Replies: 3
    Last Post: 03-26-2009, 11:42 AM
  4. Help with Errors in Inventory Program
    By ljk8950 in forum AWT / Swing
    Replies: 3
    Last Post: 08-09-2008, 12:49 AM
  5. 3 errors and then terminate program
    By hezfast2 in forum New To Java
    Replies: 2
    Last Post: 05-20-2008, 02:57 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •