Click here to Skip to main content
15,886,806 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need help to solve this problem, i wanna count strings with 2 Stringrequest..
here's my code :

Java
private void getDetail() {

        StringRequest stringRequest = new StringRequest(Request.Method.GET, "...",
                new Response.Listener<String>() {
                    @Override
                    public void onResponse(String response) {
                        try {
                            JSONObject obj = new JSONObject(response);
                            JSONArray movieArray = obj.getJSONArray("data");
                            int number1 = 0;

                            for (int i = 0; i < movieArray.length(); i++) {

                                JSONObject movieObject = movieArray.getJSONObject(i);

                                approvalfulldaymodel movieItem = new approvalfulldaymodel(
                                        movieObject.getString("id_full_day"),
                                        movieObject.getString("no_pengajuan_full_day"),
                                        movieObject.getString("tanggal_pengajuan"),
                                        movieObject.getString("lokasi_struktur"),
                                        movieObject.getString("nama_karyawan_struktur"),
                                        movieObject.getString("jenis_full_day"),
                                        movieObject.getString("start_full_day"),
                                        movieObject.getString("karyawan_pengganti"),
                                        movieObject.getString("ket_tambahan"),
                                        movieObject.getString("status_full_day"),
                                        movieObject.getString("feedback_full_day"));


                                if (movieObject.getString("status_full_day").contains("0"))
                                    number1++;
                                {
                                    izincount.setText(String.valueOf(number1));
                                }

                                movieItemList1.add(movieItem);

                            }
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }
                },
                new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError error) {
                        Toast.makeText(getApplicationContext(), "Ada kesalahan", Toast.LENGTH_SHORT).show();
                    }
                });

        StringRequest stringRequest2 = new StringRequest(Request.Method.GET, "...",
                new Response.Listener<String>() {
                    @Override
                    public void onResponse(String response) {
                        try {
                            JSONObject obj = new JSONObject(response);
                            JSONArray movieArray = obj.getJSONArray("data");
                            int number = 0;

                            for (int i = 0; i < movieArray.length(); i++) {

                                JSONObject movieObject = movieArray.getJSONObject(i);

                                approvalnonfullmodel movieItem = new approvalnonfullmodel(
                                        movieObject.getString("id_non_full"),
                                        movieObject.getString("no_pengajuan_non_full"),
                                        movieObject.getString("tanggal_pengajuan"),
                                        movieObject.getString("lokasi_struktur"),
                                        movieObject.getString("nama_karyawan_struktur"),
                                        movieObject.getString("jenis_non_full"),
                                        movieObject.getString("tanggal_non_full"),
                                        movieObject.getString("ket_tambahan_non_full"),
                                        movieObject.getString("status_non_full"),
                                        movieObject.getString("feedback_non_full"));

                                if (movieObject.getString("status_non_full").contains("0"))
                                    number++;
                                {
                                    izinnoncount.setText(String.valueOf(number));
                                }
                                movieItemList2.add(movieItem);

                                jumlahizin.setText(String.valueOf(number));

                            }
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }

                    }
                },
                new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError error) {
                        Toast.makeText(getApplicationContext(), "Silahkan Masukkan Tanggal Dengan Benar", Toast.LENGTH_SHORT).show();
                    }
                });
        RequestQueue requestQueue = Volley.newRequestQueue(this);
        requestQueue.add(stringRequest);
        requestQueue.add(stringRequest2);
    }


What I have tried:

Java
int a = number1;
int b = number;
int tambah = a + b;
jumlahizin.setText(String.valueOf(tambah));


in int a (Located in stringRequest), it turns red and error
Posted
Updated 18-Oct-20 17:51pm
v3
Comments
Richard MacCutchan 19-Oct-20 4:12am    
I cannot see those lines inside your main code.
Komang Putra 21-Oct-20 3:00am    
sorry, i remove it because it won't work
Richard MacCutchan 21-Oct-20 3:14am    
Well then we have no idea what your problem is.
David Crow 19-Oct-20 8:12am    
If you are referring to jumlahizin, it has not been declared. If not, you need to better explain what "it turns red and error" means.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900