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();