title: How do I dynamically update a spinner using ArrayList?
body: <p>I have created a <code>Spinner</code> that is populated with an <code>ArrayList</code>. I want to dynamically add values to the <code>ArrayList</code>, so the the <code>Spinner</code> populates dynamically. However, when I try to add values to my <code>ArrayList</code>, I get a <code>NullPointerException</code>.</p>
  
  <p>What am I missing?  Do I have to reset the adapter before amending the <code>ArrayList</code>?</p>
  
  <p>Here is my code:</p>
  
  <p>My spinner, arraylist, and adapter:</p>
  
  <pre><code>deleteselection = (Spinner)view.findViewById(R.id.deletespinner);
  portfoliosdelete = new ArrayList&lt;String&gt;();
  portfoliosdelete.add("Select Portfolio");
  adapterdeletetype = new ArrayAdapter&lt;String&gt;(this, android.R.layout.simple_spinner_item,portfoliosdelete){
  
      @Override
      public View getDropDownView(int position, View convertView, ViewGroup parent)
      {
          View v = null;
  
          // If this is the initial dummy entry, make it hidden
          if (position == 0) {
              TextView tv = new TextView(getContext());
              tv.setHeight(0);
              tv.setVisibility(View.GONE);
              v = tv;
          }
          else {
              // Pass convertView as null to prevent reuse of special case views
              v = super.getDropDownView(position, null, parent);
          }
  
          // Hide scroll bar because it appears sometimes unnecessarily, this does not prevent scrolling
          parent.setVerticalScrollBarEnabled(false);
          return v;
      }
  };
  adapterdeletetype.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
  deleteselection.setAdapter(adapterdeletetype);
  </code></pre>
  
  <p>My code to dynamically update spinner:</p>
  
  <pre><code> else if(users.contains(usernull)){
      pn1 = enterportfolioname.getText().toString();
      user1 = new PortfolioRecord(pn1, "someemail@gmail.com");
      users.remove(usernull);
      users.add(user1);
      portfoliosdelete.add(pn1); // &lt;-- This causes a null pointer exception
      adapterdeletetype.notifyDataSetChanged();
      portfoliolist.invalidateViews();
  </code></pre>