So my code so far is this...
import javax.swing.*;
public class TestNo2{
public static void main(String[] args){
String[] nameNum = new String[0];
int numberNames;
JTextField inputName = new JTextField(5);
JPanel nameWindow = new JPanel();
nameWindow.add(new JLabel("How many names would you like to sort?"));
nameWindow.add(inputName);
int numNames = JOptionPane.showConfirmDialog(null, nameWindow
,"Accept and sort list of students."
,JOptionPane.OK_CANCEL_OPTION);
if(numNames == JOptionPane.OK_OPTION){
String numNamesS = inputName.getText();
numberNames = Integer.parseInt(numNamesS);
nameNum = new String[numberNames];
for(int counterOne=0;counterOne<nameNum.length;counterOne++){
for(int counterTwo=1;counterTwo<=nameNum.length;counterTwo++){
nameNum[numberNames] = JOptionPane.showInputDialog(null
,"Enter the name of student "+counterTwo
,"Name Input"
,JOptionPane.QUESTION_MESSAGE);
}
}
}
}
}
There's no error when I build it but when I run the program, I would only be allowed to enter one name then the error occurs.
This is the error that shows up.
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 3 at TestNo2.main(TestNo2.java:23)
Thank you for your time in reading this.