Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

287
Vistas
Java: array not receiving values

Here's the code. list is a global variable.

    ArrayList<LatLng> list = new ArrayList<LatLng>();

    public void addCoordinate(double a, double b){
        list.add(new LatLng(a,b));
    }

public ArrayList<LatLng> readItems(int ignore) throws JSONException {
    addCoordinate(2.0,2.0);


    JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST,
            showUrl, new Response.Listener<JSONObject>() {
        @Override
        public void onResponse(JSONObject response) {
            System.out.println(response.toString());
            try {
                JSONArray records = response.getJSONArray("locations");
                for (int i = 0; i < records.length(); i++) {
                    JSONObject locations = records.getJSONObject(i);

                    double latitude = locations.getDouble("Latitude");
                    double longitude = locations.getDouble("Longitude");
                   // double lat = Double.parseDouble(latitude);
                   // double lng = Double.parseDouble(longitude);
                    list.add(new LatLng(latitude,longitude));
                }
                addCoordinate(3.0,3.0);
            } catch (JSONException e) {
                e.printStackTrace();
            }

        }
    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            System.out.append(error.getMessage());

        }
    });
    //requestQueue.add(jsonObjectRequest);

    addCoordinate(1.0,1.0);
    return list;
}

It only returns the two values when getCoordinate is called, (the 1,1 and the 2,2) but it skips over the (3,3). If anyone has a fix I would appreciate it thanks.

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

(3,3) will get added only after onResponse is called.

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda