I have a class country with an arraylist that stores countries. I have created a get and set to add and get items from specified indexes from the array list but i wont work. Whenever i call an index from the arraylist i get an out of bounds exception because the array is empty or at least seems to be.
public class country extends Application {
public ArrayListcountryList = new ArrayList ();
public String Name;
public String Code;
public String ID;
public country()
{
}
public country(String name, String id, String code)
{
this.Name = name;
this.ID = id;
this.Code = code;
}
public void setCountry(country c)
{
countryList.add(c);
}
public country getCountry(int index)
{
country aCountry = countryList.get(index);
return aCountry;
}
to call the setter i use.
country ref = new country();
ref.setCountry(new country (sName, ID, Code));
then when i want to get an index
String name = ref.countryList.get(2).Name;
i have done the same thing but used a local arraylist and it populated fine and i was able to display the names so the datasource isnt the problem its whatever im doing wrong setting and getting the data inside the arraylist in the country class
.
stackoverflow.comm
No comments:
Post a Comment