Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/186.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/meteor/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android google maps API 2在org.json.JSONArray.get(JSONArray.java:263)上获得了JSONException:org.json.JSONException:Index 0超出范围[0..0)_Android_Google Maps Android Api 2 - Fatal编程技术网

Android google maps API 2在org.json.JSONArray.get(JSONArray.java:263)上获得了JSONException:org.json.JSONException:Index 0超出范围[0..0)

Android google maps API 2在org.json.JSONArray.get(JSONArray.java:263)上获得了JSONException:org.json.JSONException:Index 0超出范围[0..0),android,google-maps-android-api-2,Android,Google Maps Android Api 2,我正在18个地点之间绘制路线,以绘制google map v2。当我开始提取路线时,它会绘制路线,但有时它不会绘制路线,并在org.json.JSONArray.get(JSONArray.java:263)上给出JSONException:org.json.JSONException:Index 0超出范围[0..0) 它还提供了“错误消息”:“您已经超过了此API的每日请求配额。” “路线”:[] “状态”:“超出查询限制” 公共类JSONParser{ 静态InputStream为空; 静

我正在18个地点之间绘制路线,以绘制google map v2。当我开始提取路线时,它会绘制路线,但有时它不会绘制路线,并在org.json.JSONArray.get(JSONArray.java:263)上给出
JSONException:org.json.JSONException:Index 0超出范围[0..0)

它还提供了
“错误消息”:“您已经超过了此API的每日请求配额。”
“路线”:[]
“状态”:“超出查询限制”

公共类JSONParser{
静态InputStream为空;
静态JSONObject jObj=null;
静态字符串json=“”;
//建造师
公共JSONParser(){
}
公共字符串getJSONFromUrl(字符串url){
//发出HTTP请求
试一试{
//defaultHttpClient
DefaultHttpClient httpClient=新的DefaultHttpClient();
HttpPost HttpPost=新的HttpPost(url);
HttpResponse HttpResponse=httpClient.execute(httpPost);
HttpEntity HttpEntity=httpResponse.getEntity();
is=httpEntity.getContent();
}捕获(不支持的编码异常e){
e、 printStackTrace();
}捕获(客户端协议例外e){
e、 printStackTrace();
}捕获(IOE异常){
e、 printStackTrace();
}
试一试{
BufferedReader reader=新的BufferedReader(新的InputStreamReader(
is,“iso-8859-1”),8);
StringBuilder sb=新的StringBuilder();
字符串行=null;
而((line=reader.readLine())!=null){
sb.追加(第+行“\n”);
}
json=sb.toString();
is.close();
}捕获(例外e){
Log.e(“缓冲区错误”,“错误转换结果”+e.toString());
}
Log.d(“JSON_RUTA”,JSON);
返回json;
}
}
私有字符串makeURL(双sourcelat、双sourcelog、双destlat、,
双日志,字符串模式)
{
StringBuilder urlString=新的StringBuilder();
如果(模式==null)
mode=“驾驶”;
urlString.append(“http://maps.googleapis.com/maps/api/directions/json");
urlString.append(“?origin=”);//来自
append(Double.toString(sourcelat));
urlString.append(“,”);
append(Double.toString(sourcelog));
urlString.append(“&destination=”);//到
append(Double.toString(destlat));
urlString.append(“,”);
append(Double.toString(destlog));
追加(“&sensor=false&mode=“+mode+”&units=metric”);
返回urlString.toString();
}
私有列表(字符串编码)
{
List poly=new ArrayList();
int index=0,len=encoded.length();
int lat=0,lng=0;
while(指数>1):(结果>>1));
lat+=dlat;
移位=0;
结果=0;
做
{
b=编码的.charAt(索引++)-63;
结果|=(b&0x1f)=0x20);
int-dlng=((结果&1)!=0?~(结果>>1):(结果>>1));
液化天然气+=液化天然气;
LatLng p=新LatLng(((双)lat/1E5)),((双)lng/1E5));
poly.add(p);
}
返回多边形;
}
尝试
{
//将字符串转换为json对象
最终JSONObject json=新JSONObject(结果);
JSONArray routarray=json.getJSONArray(“路由”);
JSONObject routes=routeArray.getJSONObject(0);
JSONObject overviewPolylines=routes.getJSONObject(“overview_Polylines”);
encodedString=概览多段线.getString(“点”);
列表=解码多边形(编码字符串);
}捕获(JSONException e)
{
e、 printStackTrace();
}
对于(intz=0;z
有谁能告诉我解决这个问题的办法吗? 提前谢谢


我以前也遇到过同样的问题,这不是因为Json。这是因为在一段时间内向谷歌发送了太多的请求。所以我只是放慢了向谷歌发送帖子的频率,再也没有看到过这条消息。

@ohyes的意思是你发送了多个(太多)邮件在太短的时间内使用API密钥向google发出请求(例如,一分钟内超过100次,仅举一个例子)

因此,您将收到
OVER\u QUERY\u LIMIT
和空JSON数组

您应该考虑更改请求之间的时间,还应该验证接收到的数组是否有任何元素

try
{
    // Tranform the string into a json object
    final JSONObject json = new JSONObject(result);
    JSONArray routeArray = json.getJSONArray("routes");
    if(routeArray.size() > 0) {
        JSONObject routes = routeArray.getJSONObject(0);
        JSONObject overviewPolylines = routes.getJSONObject("overview_polyline");
        encodedString = overviewPolylines.getString("points");

        List<LatLng> list = decodePoly(encodedString);
    }
} catch (JSONException e)
{
    e.printStackTrace();
}
试试看
{
//将字符串转换为json对象
最终JSONObject json=新JSONObject(结果);
JSONArray routarray=json.getJSONArray(“路由”);
如果(routeArray.size()>0){
JSONObject routes=routeArray.getJSONObject(0);
JSONObject overviewPolylines=routes.getJSONObject(“overview_Polylines”);
encodedString=概览多段线.getString(“点”);
列表=解码多边形(编码字符串);
}
}捕获(JSONException e)
{
e、 printStackTrace();
}
这可以解决抛出的异常,但不能解决您没有得到结果的事实,可能是因为请求太多

编辑:

OVER\u QUERY\u LIMIT
事件发生(可能)是因为对
getJSONFromUrl()
函数的调用太快。请添加进行这些调用的代码,以便我们可以尝试并在
try
{
    // Tranform the string into a json object
    final JSONObject json = new JSONObject(result);
    JSONArray routeArray = json.getJSONArray("routes");
    if(routeArray.size() > 0) {
        JSONObject routes = routeArray.getJSONObject(0);
        JSONObject overviewPolylines = routes.getJSONObject("overview_polyline");
        encodedString = overviewPolylines.getString("points");

        List<LatLng> list = decodePoly(encodedString);
    }
} catch (JSONException e)
{
    e.printStackTrace();
}