I am working on inserting a list of array inside an object. Using that object I have created, I am planning to use it inside another object as it is required to use it in my JTable.
This is my object class.
class MyData {
private String name;
public MyData(String name) {
this.name = name;
}
}
My main class is:
String[] tt = {"aa"};
MyData[] thePlayers = new MyData[0];
for(int i = 0;i < tt.length;i++){
thePlayers[i] = new MyData(tt[i]);
}
Object[][] data = {{"2"}};
String[] headers = { "Income Type" };
JTable table = new JTable(data, headers);
I am receiving this error on my system Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
What might be the cause of it? Ive tried all means, but I still cant figure it out.
UPDATE
I encounter a different hurdle which is initializing Object[][].
Example :
Object[][] data;
How do we initialize this in a forloop using above code we have applied in ThePlayers?
Lastly, when i run the program, it didnt display as what is specified in the array.