Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

291
Views
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 answers
Answer question

0

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

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!