PDA

Click to See Complete Forum and Search --> : Error Creating ArrayLists


fundean
Jan 26th, 2005, 08:57 AM
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 !

crptcblade
Jan 26th, 2005, 09:02 AM
Throw an import statement in for java.util.* at the top of the file.

Dillinger4
Jan 26th, 2005, 02:13 PM
fundean you asked the same question not too long ago.

System_Error
Jan 26th, 2005, 02:38 PM
There's a lot more wrong than just the import statement.


//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;
}
}
}

System_Error
Jan 26th, 2005, 02:39 PM
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.

Dillinger4
Jan 26th, 2005, 08:45 PM
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.

System_Error
Jan 27th, 2005, 05:23 AM
ahh I see. I wonder if he didn't like how you wrote it in 1.5..