Я пытаюсь установить текст в JFrame с помощью setText. Он работает, однако после нескольких запусков программы я начинаю получать ArrayIndexOutOfBounds, однако текст все еще обновляется. Я не уверен, что вызывает проблему.
Исключение в потоке «AWT-EventQueue-0» java .lang.ArrayIndexOutOfBoundsException: 1> = 1
if (updatingVairablesWithUser == true) {
DefaultListModel model = new DefaultListModel();
userClient.locationsList.setModel(model);
int cityNameCount = 0;
while ((line = input.readLine()) != null) {
if (line.contains("Nottingham")) {
model.addElement("Nottingham");
// Add Substring to Linked List
line = line.substring(0, 5);
Nottingham.add(line);
// Check if Nottingham doesn't already exist in the list
for (int i = 0; i < model.getSize(); i++) {
// Get name of Element At Index
String temp = (String) model.getElementAt(i);
// If it is the same as the city name add 1 Count of that City Name
if (temp.contains("Nottingham")) {
cityNameCount++;
}
if (cityNameCount == 2) {
model.remove(i);
cityNameCount = 0;
}
}
if (London.size() >= 3 || Nottingham.size() >= 3) {
if (model.capacity() > 0 && userClient.locationsList.isSelectionEmpty()) {
userClient.locationsList.setSelectedIndex(0);
}
String selectedValue = userClient.locationsList.getSelectedValue();
switch (selectedValue) {
case "-1":
System.out.println("Nothing Selected");
case "Nottingham":
userClient.currentLocation.setText("Nottingham");
userClient.currentTemperature.setText(Nottingham.get(0));
userClient.currentHumidity.setText(Nottingham.get(1));
userClient.currentPosition.setText(Nottingham.get(2));
System.out.println(Nottingham.get(0));
userClient.repaint();
userClient.revalidate();
Nottingham.clear();
break;
}
}
}
}