I am coding in a basic pin and user id system but I can't seem to figure out this indexing issue. I understand that arrays are indexed at 0 and in my code I am going through in a while loop (I tried a for loop but got the same issue) checking the i'th position of the array with the entered pin. for whatever reason I am getting this error:
Process: com.example.gabeskillerpcjr.assemblylineapp, PID: 17838 java.lang.ArrayIndexOutOfBoundsException: length=3; index=3
at com.example.gabeskillerpcjr.assemblylineapp.FourDtForm.exportVarifaction(FourDtForm.java:350)
at com.example.gabeskillerpcjr.assemblylineapp.FourDtForm$3.onClick(FourDtForm.java:264)
Here is my simple while loop, int i is initialized at 0:
public void exportVarifaction(){
String[] PinsNums = new String[]{"1415","1678","1923"};
String[] PinNames = new String[]{"admin","test","test1"};
String tmp;
boolean done = false;
while (!done) {
tmp = PinsNums[i];
if (tmp.equals(keyPadNumsEntered)) {
result = PinNames[i];
loggedOn = true;
done = true;
} else {
++i;
result = "no logon";
}
}
}
doneto true ifi >= PinsNums.length; Iftmpnever equalskeyPadNumsEntered, it will increment and never be done.iset to zero? It should right before the loop starts, otherwise it might start at the wrong number depending on how many times this executes.