ArrayIndexOutOfBoundsException: 1 error when using String[] and split()

Hello,

I tried different options and could not confirm your suspicion.

String [] list = {"0", "0", "0", "0", "0", "0", "0", "0", "0", "0"};
String elevenList = "0,1,2,3,4,5,6,7,8,9";
String tenList = "0,1,2,3,4,5,6,7,8,9";
String nineList = "0,1,2,3,4,5,6,7,8";
String empty = "";
String missing = null;
printArray(list);
list=split(elevenList, ',');
printArray(list);
list=split(tenList, ',');
printArray(list);
list=split(nineList, ',');
printArray(list);
list=split(empty, ',');
printArray(list);
list= split(missing, ',');
printArray(list);

neither getting a too many, to few, empty or null array from split seems to be a problem…

in my experience an ArrayIndexOutOfBoundsException event happens when you try to access or write to a specific element of an array that is not there
my only suspicion is that, if you get a smaller number of ten values, your text() routine may complain.

you could rule that out by using the current length of your array.

 for (int i=0;i< snsrTempList.length;i++) {
    text("Sensor" + i,40,110 + i * 20);
    text(snsrTempList[i],120,110 + i * 20);
  }

you could get another ArrayIndexOutOfBoundsException if the array = null.
but you can rule that out again by only updating the array if it is not null:

void serialEvent(Serial p) { 
  if (p == espUSBPort) {
    inString = p.readString();
    if (inString.length() < 62 && inString.length != null) {
      snsrTempList = split(inString, ',');
    }
  }
}

hope that helps