The err variable contains a message. The format will be the same but the value -1 will change accordingly.

String err = "Result:-1|Error|sSide: Value Must Be Either b|s."

Therefore I attempted to retrieve -1 value from err variable using the code below:

String[] temp2 = err.trim().split(":");
StringTokenizer st = new StringTokenizer(temp2[1],"|");
  int x = Integer.parseInt(st.nextToken());
catch(NumberFormatException nFE){

However I am getting wrong results.

Your help is kindly appreciated.



"wrong results" doesn't help identify anything.
But, it's probably easier & quicker to use indexOf to get the indices of the first ':' and '|' and substring the part between those two indexes.