PolyUtil.decode Throwing StringIndexOutOfBoundsException

问题描述 投票:1回答:1

[使用Google Maps PolyUtil.decode时,出现此错误java.lang.StringIndexOutOfBoundsException: length=60; index=60 at java.lang.String.charAt(Native Method) at com.google.maps.android.PolyUtil.decode(PolyUtil.java:464)当我跟踪错误时,它给了我PolyUtil.class,然后将我带到该特定行

do{
  b = encodedPath.charAt(index++) - 63 - 1;
  result += b << shift;
  shift += 5;
} while(b >= 31);

但是到目前为止,仅针对特定的编码字符串会引发此错误。当我解码另一个字符长度相同或长度更长或更短的编码字符串时,不会引发错误。我什至使用Google的Interactive Polyline Decoder Tool测试了给出错误的字符串,并且该字符串正确显示。引发此错误的任何原因都发生了吗?

android google-maps google-polyline polylineoptions
1个回答
0
投票

问题是双反斜杠“ \\”。在解码之前,只需用一个反斜杠“ \”替换它们即可。如下:

String newEncodedString = encodedString.replace("\\\\","\\");
PolyUtil.decode(newEncodedString);
© www.soinside.com 2019 - 2024. All rights reserved.