The error message "java.lang.ArrayIndexOutOfBoundsException: length=1; index=1" indicates that the array "parts" has a length of 1, which means it only contains one element. Therefore, trying to access the second element (index 1) will result in an "ArrayIndexOutOfBoundsException" error.
This error can occur if the delimiter "/" is not found in the string "coordenadas". To avoid this error, you can check the length of the "parts" array before accessing its elements. Here's an example:
String coordenadas = message.toString();
String[] parts = coordenadas.split("/");
if (parts.length >= 2) {
longitudMensajeArrived = parts[0];
latitudMensajeArrived = parts[1];
} else {
// handle the case where the delimiter is not found
}
In this example, we first split the string "coordenadas" using the delimiter "/". Then, we check if the length of the "parts" array is greater than or equal to 2. If it is, we can safely access the first and second elements of the array. Otherwise, we handle the case where the delimiter is not found.
By checking the length of the "parts" array before accessing its elements, we can avoid the "ArrayIndexOutOfBoundsException" error.