When you're getting an ArrayIndexOutOfBoundsException when calling parts[1], but not when calling parts[0], we can conclude that parts.length == 1. Hence, since indices start at 0, index 0 contains the whole string, and index 1 in the split array (and up) doesn't exist.
--> Problem found: Your datareceived doesn't contain a &, hence it won't be split anywhere.
Solution: Hoping I understood your problem correctly (checking whether a string datareceived contains a value at certain indices), I wrote you a piece of code that should work.
String datareceived = "01234";
int index1 = 2;
int index2 = 5;
if (datareceived.length() > index1) {
//the string has a value at index1. With the given example, this if-query would be true.
}
if (datareceived.length() > index2) {
//the string has a value at index2. With the given example, this if-query would be false.
}
Side-note when using .split:
I found that, when using String.split("expression"), the "expression" part can contain regex-codes (regular expression). Therefore, if you're using any symbol that is a valid regex expression (such as . or $), it will not work (at least, not necessarily). For example, in regex, . means "any character", which will essentially give you an empty array.
(Note: I'm no regex expert, but "&" doesn't appear to be a valid regular expression)
Example:
String s = "a,b";
String[] strings = s.split(",");
for (String str : strings) {
System.out.println(str + "_");
}
//will print out "a_b_"
Example (not working as desired):
String s = "a.b";
String[] strings = s.split(".");
//"strings" is an empty array, since "a", ".", and "b" are "any character".
Solution:
instead of .split("."), use .split("\\.")
parts.length(length is not a function).