title: NullPointerException even though nothing is null?
body: <p>I have looked through all of my code, but I can't find any null references, so I am lost. I am saving certain contacts the the user collects into shared preferences:</p>
  
  <pre><code>   public void saveContacts() {
  
          contacts = this.getSharedPreferences("contacts", MainActivity.MODE_PRIVATE); //Making a shared preferences
  
          Set&lt;String&gt; set = new HashSet&lt;String&gt;();
          set.addAll(contactArrayList); 
  
          contactEditor.clear(); //Clearing current values in shared pref
          contactEditor.putStringSet("contactSetKey", set); //Adding contacts
          contactEditor.commit();
  
          Toast.makeText(MainActivity.this, "Contacts have been saved!", Toast.LENGTH_SHORT).show();
      }
  </code></pre>
  
  <p>Here is where I get the contacts:</p>
  
  <pre><code>@Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
  
          contactArrayList= new ArrayList&lt;String&gt;();
          listview = (ListView) findViewById(R.id.listView);
  
          arrayAdapter = new ArrayAdapter (this, android.R.layout.simple_list_item_1, contactArrayList);
          listview.setAdapter(arrayAdapter);
  
          loadSavedStuff();
  
  
      }
  
      public void loadSavedStuff() {
          //CLEAR CONTENTS OF ARRAYLIST AND GET THEM FROM SHARED PREFERENCE
  
  
          if(contacts.getStringSet("contactSetKey", null) != null) {
              contactArrayList.clear();
              contactArrayList = new ArrayList&lt;String&gt;(contacts.getStringSet("contactSetKey", null));
              arrayAdapter.notifyDataSetChanged();
          }
      }
  </code></pre>
  
  <p>I have been adding stuff to my list like so:</p>
  
  <pre><code>  contactArrayList.add(contactName +" - " +contactNumber);
              arrayAdapter.notifyDataSetChanged();
  </code></pre>
  
  <p>My null pointer exception is here:</p>
  
  <pre><code>  Caused by: java.lang.NullPointerException: Attempt to invoke interface method 'java.util.Set android.content.SharedPreferences.getStringSet(java.lang.String, java.util.Set)' on a null object reference
  </code></pre>
  
  <p>Pointing here:</p>
  
  <pre><code>    if(contacts.getStringSet("contactSetKey", null) != null) {
  </code></pre>
  
  <p>and here:</p>
  
  <pre><code>    loadSavedStuff();
  </code></pre>