Hello I have been trying to add a String
to a String[]
. Here is what I have,
static String[] ipList = {"127.0.0.1", "173.57.51.111", "69.696.69.69"};
@Override
public void actionPerformed(ActionEvent e) {
String newIpGet = textfield.getText();
try {
for ( int i = 0; i < Main.ipList.length; i++){
Main.ipList[i+1] = newIpGet.toString(); // <---- *****
Main.write(Main.ipList[i]);
}
} catch (IOException e1) {
e1.printStackTrace();
}
Main.amountOfIps = Main.amountOfIps + 1;
System.out.println("Text Entered!");
System.out.println("There are now " +Main.ipList.length + " Ips.");
textfield.setVisible(false);
label.setVisible(true);;
}
But, I keep getting java.lang.ArrayIndexOutOfBoundsException
because it wont let me make any new String
s. I can't modify my declaration of ipList[]
without a lot of modifications, what can I do?