-1

I'm confused about this problem I've already tried this query before but when I tried applying it inside of my Custom Dialog it returns an error

I have an error with this line requestQueue.add(jsonObjectRequest); it crashes my app, any idea? need help.

ArrayList<String> patientType = new ArrayList<>();
ArrayAdapter<String> patientAdapter;
RequestQueue requestQueue;

 void showCustomDialog() {
    final Dialog dialog = new Dialog(HomeActivity.this);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.setCancelable(true);
    dialog.setContentView(R.layout.custom_dialog);
    final EditText nameEt = dialog.findViewById(R.id.name_et);
    final Spinner ageEt = dialog.findViewById(R.id.spnAppointmentCat);
    Button submitButton = dialog.findViewById(R.id.submit_button);

    nameEt.setFocusable(false);
    nameEt.setClickable(true);
    patientType.clear();
    String url = "http://192.168.222.222/test/populatePatientType.php";
    JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST,
            url, null, new Response.Listener<JSONObject>() {
        @Override
        public void onResponse(JSONObject response) {
            try {
                JSONArray jsonArray = response.getJSONArray("patient_type");
                for(int i=0; i<jsonArray.length();i++){
                    JSONObject jsonObject = jsonArray.getJSONObject(i);
                    String countryName = jsonObject.optString("type");
                    patientType.add(countryName);
                    patientAdapter = new ArrayAdapter<>(HomeActivity.this,
                            android.R.layout.simple_spinner_item, patientType);
                    patientAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
                    ageEt.setAdapter(patientAdapter);
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {

        }
    });
    requestQueue.add(jsonObjectRequest);   //This will return an error        
    dialog.show();
a_local_nobody
  • 7,360
  • 5
  • 25
  • 45
CarlJade
  • 79
  • 6
  • Does this answer your question? [What is a NullPointerException, and how do I fix it?](https://stackoverflow.com/questions/218384/what-is-a-nullpointerexception-and-how-do-i-fix-it) – a_local_nobody May 28 '22 at 15:15
  • you have never assigned a value to your variable, so yes, it should be null – a_local_nobody May 28 '22 at 15:15

0 Answers0