I'm having some trouble iterating through ArrayList. I have a class named Row which extends ArrayList<String>. I have another class named Table which extends ArrayList<Row>.
I am trying to iterate through the Table class to convert the ArrayList of Rows to a two-dimensional array of Strings.
Here is my code for the Table class:
public class Table extends ArrayList<Row>
{
public Row[] appArray; //Array of single applicant details
public String tableArray[][]; //Array of every applicant
private ArrayList<Row> ar;
private Row r;
public Table()
{
}
public void addApplicant(Row app)
{
add(app);
displayable();
}
public void convertToArray()
{
int x = size();
appArray=toArray(new Row[x]);
}
public void displayable()
{
int i,j;
for (Row r: ar)
i=0;
for(String s: r){
j=0;
tableArray[i][j]=s;
j++;
}
}}
and here is the Row class:
public class Row extends ArrayList<String>
{
public Row(String appNumber, String name, String date, String fileLoc, String country, Table table)
{
addDetails(appNumber,name,date,fileLoc,country);
table.addApplicant(this);
}
public void addDetails(String appNumber, String name, String date, String fileLoc, String country)
{
add(appNumber);
add(name);
add(date);
add(fileLoc);
add(country);
}}
The method i am having trouble with is displayable() in the Table class. It tells me i may not have been initialized However if I initialize it in the second for each loop it will only iterate through the first element in my Table ArrayList?
Thanks in advance for any pointers.
iandjto0inside their respectiveforloops seems like a possible logic error to me.ArrayList<Object<String>>, because classObjectdoes not have type parameters (Object<String>is invalid).