I have the following arrays:JTextArea foxBA, foxMA, foxBP, foxMLS;
JTextArea[] textFox = {foxBA, foxMA, foxBP, foxMLS};
String[] label = {"Breeding Age: ", "Max Age: ", "Breeding Probability: ", "Max Litter Size: "};
I initialize them by doing:for(int i = 0; i < textFox.length; i++){
tab2_fox.add(new JLabel(label[i]));
textFox[i] = new JTextArea(1, 5);
textFox[i].setText(Fox.getData().get(i).toString());
tab2_fox.add(textFox[i]);
}
However, when trying to get the text by doingfoxBA.getText()
I get a NullPointerException. But when doing textFox[0].getText()
everything works fine. Why can't I acces the actual object, but can I acces it by using its array reference?