Java:数组未接收值

Java:数组未接收值,java,android,arraylist,Java,Android,Arraylist,这是密码。列表是一个全局变量 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 {

这是密码。列表是一个全局变量

    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;
}
ArrayList list=new ArrayList();
公共空间添加坐标(双a、双b){
增加(新板条(a、b));
}
公共ArrayList readItems(int ignore)抛出JSONException{
add坐标(2.0,2.0);
JsonObjectRequest JsonObjectRequest=新的JsonObjectRequest(Request.Method.POST,
showUrl,新的Response.Listener(){
@凌驾
公共void onResponse(JSONObject响应){
System.out.println(response.toString());
试一试{
JSONArray records=response.getJSONArray(“位置”);
for(int i=0;i

它仅在调用getCoordinate时返回两个值(1,1和2,2),但跳过(3,3)。如果有人有修复方法,我将不胜感激。只有在调用onResponse后才会添加(3,3)。

我想你不明白截击是如何工作的。您的请求在方法返回后完成,这里是getCoordinate()?您能否至少发布所涉及的完整方法?由于
requestQueue.add
被注释掉,因此请求从未发生过anyway@pulp_fictionaddCoordinate在顶部…@Chadderz:不,不是。我做了一个Ctrl+FjsonObjectRequest.onResponse(..),然后检查列表中的值。