我的微调器未从json数据填充

时间:2019-08-27 09:18:49

标签: android json android-volley spinner

我的微调器没有填充JSON数据

所以我的应用中有3个微调器,其中一个微调器没有填充json数据

我为微调器使用的代码基本上是相同的,所以我不明白为什么它不填充有效列表和无效列表之间唯一的区别是数组列表名称和值

非正常旋转

      private void loadSpinnerData3(String url) {

    RequestQueue requestQueue=Volley.newRequestQueue(getApplicationContext());
    StringRequest stringRequest=new StringRequest(Request.Method.GET, url, new Response.Listener<String>() {
        @Override
        public void onResponse(String response) {


            try {
                JSONObject jsonObject=new JSONObject(response);

                if (jsonObject.getInt("success") == 1) {

                    JSONArray jsonArray=jsonObject.getJSONArray("Status");
                    for (int i=0; i < jsonArray.length(); i++) {
                        JSONObject jsonObject1=jsonArray.getJSONObject(i);

                        String upload=jsonObject1.getString("reason");
                        UploadingError.add(upload);
                    }
                }

                spinner3.setAdapter(new ArrayAdapter<>(SecondActivity.this, android.R.layout.simple_spinner_dropdown_item, UploadingError));


                if (jsonObject.getInt("failed") == 1) {
                    JSONArray jsonArray=jsonObject.getJSONArray("Errors");
                    for (int i=0; i < jsonArray.length(); i++) {
                        JSONObject jsonObject1=jsonArray.getJSONObject(i);

                        String error=jsonObject1.getString("reason");
                        UploadingError.add(error);

                    }
                    spinner3.setAdapter(new ArrayAdapter<>(SecondActivity.this, android.R.layout.simple_spinner_dropdown_item, UploadingError));
                }

            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
        }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {

            error.printStackTrace();
        }
    });
    int socketTimeout=30000;
    RetryPolicy policy=new DefaultRetryPolicy(socketTimeout, DefaultRetryPolicy.DEFAULT_MAX_RETRIES, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT);
    stringRequest.setRetryPolicy(policy);

    requestQueue.add(stringRequest);


}

工作纺机

        private void loadSpinnerDataError2(String url) {

    RequestQueue requestQueue=Volley.newRequestQueue(getApplicationContext());
    StringRequest stringRequest=new StringRequest(Request.Method.GET, url, new Response.Listener<String>() {
        @Override
        public void onResponse(String response) {


            try {
                JSONObject jsonObject=new JSONObject(response);

                if (jsonObject.getInt("failed") == 1) {

                    JSONArray jsonArray=jsonObject.getJSONArray("Errors");
                    for (int i=0; i < jsonArray.length(); i++) {
                        JSONObject jsonObject1=jsonArray.getJSONObject(i);

                        String error=jsonObject1.getString("reason");
                        Errors.add(error);
                    }
                }

                spinner.setAdapter(new ArrayAdapter<>(SecondActivity.this, android.R.layout.simple_spinner_dropdown_item, Errors));
                Toast.makeText(SecondActivity.this, spinner.getSelectedItem().toString(), Toast.LENGTH_LONG).show();


            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            error.printStackTrace();
        }
    });
    int socketTimeout=30000;
    RetryPolicy policy=new DefaultRetryPolicy(socketTimeout, DefaultRetryPolicy.DEFAULT_MAX_RETRIES, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT);
    stringRequest.setRetryPolicy(policy);

    requestQueue.add(stringRequest);
}

0 个答案:

没有答案