title: Spinner not working in Android
body: <p>There are two spinners in my application.when i select a value from one spinner, according to the selection, values will be loaded to second spinner. The problem is when i select the second spinner, the application unfortunately stops. Thanks in advance.</p>
  
  <pre><code>public class CreateAppointment extends AppCompatActivity {
  
  String[] lect_name = new String[100];
  String[] spinner_subjects_load;
  Spinner spSubject,spLecturer;
  String chosedSubject;
  String chosedLectName;
  String chosedDateString;
  RequestQueue requestQueue;
  String url = "http://quick-appointment.b2creations.net/getLecturerNames.php";
  CustomRequest customRequest;
  String dayOfWeekString;
  Calendar currentDate,chosedDate;
  User user;
  
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_create_appointment);
      Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
      setSupportActionBar(toolbar);
  
      Intent intent = getIntent();
      user = (User) intent.getExtras().getSerializable("user");
  
      currentDate = Calendar.getInstance();
      DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
      dateFormat.format(currentDate.getTime());   //get current date
  
  
      spinner_subjects_load = new String[]{"SPDC", "HCI", "MAD", "SEIII", "SEP", "DAA", "ITP"};
  
      spSubject = (Spinner) findViewById(R.id.spSubject);
      ArrayAdapter&lt;String&gt; adapter1 = new ArrayAdapter&lt;String&gt;(this, android.R.layout.simple_spinner_item, spinner_subjects_load);
      spSubject.setAdapter(adapter1);
  
      requestQueue = Volley.newRequestQueue(this);
  
      spSubject.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
          @Override
          public void onItemSelected(AdapterView&lt;?&gt; parent, View view, int position, long id) {
  
              chosedSubject = spSubject.getSelectedItem().toString();
  
              HashMap&lt;String, String&gt; hashMap = new HashMap&lt;String, String&gt;();
              hashMap.put("subj_name", chosedSubject);
  
              customRequest = new CustomRequest(Request.Method.POST, url, hashMap, new Response.Listener&lt;JSONObject&gt;() {
                  @Override
                  public void onResponse(JSONObject response) {
                      int count = 0;
                      try {
  
                          JSONArray jsonArray = response.getJSONArray("Lecturers");
                          while (count &lt; jsonArray.length()) {
                              JSONObject jo = jsonArray.getJSONObject(count);
                              lect_name[count] = jo.getString("name");
                              count++;
                          }
  
                          spLecturer = (Spinner) findViewById(R.id.spLecturer);
  
                          ArrayAdapter&lt;String&gt; adapter2 = new ArrayAdapter&lt;String&gt;(CreateAppointment.this, android.R.layout.simple_spinner_item, lect_name);
                          adapter2.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
                          spLecturer.setAdapter(adapter2);
  
                          chosedLectName = spLecturer.getSelectedItem().toString();
                          Toast.makeText(CreateAppointment.this, chosedLectName, Toast.LENGTH_SHORT).show();
  
                      } catch (JSONException e) {
                          e.printStackTrace();
                      }
                  }
              }, new Response.ErrorListener() {
                  @Override
                  public void onErrorResponse(VolleyError error) {
  
                  }
              });
  
              requestQueue.add(customRequest);
  
          }
  
  
          @Override
          public void onNothingSelected(AdapterView&lt;?&gt; parent) {
  
          }
      });
  
  }
  </code></pre>