Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid google maps API 2 got JSONException:org.json.JSONException: Index 0 out of range [0..0) at org.json.JSONArray.get(JSONArray.java:263)
    primarykey
    data
    text
    <p>I am drawing route between 18 locations to draw the google map v2.When i start fetching routes it draws route but some times it is not drawing route and it gives <code>JSONException :org.json.JSONException: Index 0 out of range [0..0) at org.json.JSONArray.get(JSONArray.java:263)</code></p> <p>and also it gives <code>"error_message" : "You have exceeded your daily request quota for this API." "routes" : [] "status" : "OVER_QUERY_LIMIT"</code></p> <pre><code>public class JSONParser { static InputStream is = null; static JSONObject jObj = null; static String json = ""; // constructor public JSONParser() { } public String getJSONFromUrl(String url) { // Making HTTP request try { // defaultHttpClient DefaultHttpClient httpClient = new DefaultHttpClient(); HttpPost httpPost = new HttpPost(url); HttpResponse httpResponse = httpClient.execute(httpPost); HttpEntity httpEntity = httpResponse.getEntity(); is = httpEntity.getContent(); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } try { BufferedReader reader = new BufferedReader(new InputStreamReader( is, "iso-8859-1"), 8); StringBuilder sb = new StringBuilder(); String line = null; while ((line = reader.readLine()) != null) { sb.append(line + "\n"); } json = sb.toString(); is.close(); } catch (Exception e) { Log.e("Buffer Error", "Error converting result " + e.toString()); } Log.d("JSON_RUTA", json); return json; } } private String makeURL(double sourcelat, double sourcelog, double destlat, double destlog, String mode) { StringBuilder urlString = new StringBuilder(); if (mode == null) mode = "driving"; urlString.append("http://maps.googleapis.com/maps/api/directions/json"); urlString.append("?origin=");// from urlString.append(Double.toString(sourcelat)); urlString.append(","); urlString.append(Double.toString(sourcelog)); urlString.append("&amp;destination=");// to urlString.append(Double.toString(destlat)); urlString.append(","); urlString.append(Double.toString(destlog)); urlString.append("&amp;sensor=false&amp;mode=" + mode + "&amp;units=metric"); return urlString.toString(); } private List&lt;LatLng&gt; decodePoly(String encoded) { List&lt;LatLng&gt; poly = new ArrayList&lt;LatLng&gt;(); int index = 0, len = encoded.length(); int lat = 0, lng = 0; while (index &lt; len) { int b, shift = 0, result = 0; do { b = encoded.charAt(index++) - 63; result |= (b &amp; 0x1f) &lt;&lt; shift; shift += 5; } while (b &gt;= 0x20); int dlat = ((result &amp; 1) != 0 ? ~(result &gt;&gt; 1) : (result &gt;&gt; 1)); lat += dlat; shift = 0; result = 0; do { b = encoded.charAt(index++) - 63; result |= (b &amp; 0x1f) &lt;&lt; shift; shift += 5; } while (b &gt;= 0x20); int dlng = ((result &amp; 1) != 0 ? ~(result &gt;&gt; 1) : (result &gt;&gt; 1)); lng += dlng; LatLng p = new LatLng((((double) lat / 1E5)), (((double) lng / 1E5))); poly.add(p); } return poly; } try { // Tranform the string into a json object final JSONObject json = new JSONObject(result); JSONArray routeArray = json.getJSONArray("routes"); JSONObject routes = routeArray.getJSONObject(0); JSONObject overviewPolylines = routes.getJSONObject("overview_polyline"); encodedString = overviewPolylines.getString("points"); List&lt;LatLng&gt; list = decodePoly(encodedString); } catch (JSONException e) { e.printStackTrace(); } for (int z = 0; z &lt; list.size() - 1; z++) { LatLng src = list.get(z); LatLng dest = list.get(z + 1); Polyline line = mMap.addPolyline(new PolylineOptions() .add(new LatLng(src.latitude, src.longitude), new LatLng(dest.latitude, dest.longitude)).width(4) .color(Color.BLUE).geodesic(true)); line.isVisible(); } </code></pre> <p>Can any one suggest me what ll be the solutions for this? Thanks in advance.</p> <p></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload