Results 1 to 7 of 7

Thread: Error Creating ArrayLists

  1. #1

    Thread Starter
    Lively Member fundean's Avatar
    Join Date
    Apr 2001
    Posts
    98

    Error Creating ArrayLists

    public class Arrays
    {
    public static void main (String args[])
    {
    ArrayList arr = new ArrayList();
    int x = 0;
    int y = 1;
    if (x != arr.length())
    {
    arr[x] = y;
    y = y + 1;
    x = x + 1;
    }
    }
    }



    The error I get is:

    "Cannot resolve symbol class arraylist"

    Can someone suggest a fix? Thanks !

  2. #2
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091

    Re: Error Creating ArrayLists

    Throw an import statement in for java.util.* at the top of the file.
    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  3. #3

  4. #4
    Frenzied Member System_Error's Avatar
    Join Date
    Apr 2004
    Posts
    1,111

    Re: Error Creating ArrayLists

    There's a lot more wrong than just the import statement.

    Code:
    //import the right crap
    
    import java.util.*;
    
      public class Arrays
      {
          public static void main (String args[])
          {
            ArrayList arr = new ArrayList();
            int x = 0;
            int y = 1;
             
             //fill the arraylist will values
            for (int i=0; i<10; i++)
            {
    	    arr.add(i + 1);
            }
    
            if (x != arr.size())
            {
                arr.add(x,y);
                y = y + 1;
                x = x + 1;
            }
      }
    }

  5. #5
    Frenzied Member System_Error's Avatar
    Join Date
    Apr 2004
    Posts
    1,111

    Re: Error Creating ArrayLists

    The methods and way you had it setup, looked as if you were trying to use an array. The methods for an array are much different than an arraylist.

  6. #6
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418

    Re: Error Creating ArrayLists

    Yeah he seems to be confusing arrays and ArrayLists. I don't know why since he pretty much used the latter properly in one of his posts not too long ago.

  7. #7
    Frenzied Member System_Error's Avatar
    Join Date
    Apr 2004
    Posts
    1,111

    Re: Error Creating ArrayLists

    ahh I see. I wonder if he didn't like how you wrote it in 1.5..

Posting Permissions

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



Click Here to Expand Forum to Full Width