title: How to get SharedPreference from non activity class for non activity
body: <p>In my Activity class I store some data in a <code>Sharedpreference</code>. My non Activity class has getter and setter to read the <code>Sharedpreference</code> data. I want use this Data in an another Activity class. But I get always a Nullpointer exception.</p>
  
  <p>This is a Code snippet from my Activity class.</p>
  
  <pre><code>SharedPreferences prefs;
  
  prefs = getActivity().getSharedPreferences(KEY_NAME_FOR_PREF, 0);
          SharedPreferences.Editor editor = prefs.edit();
  editor.putString("name", name.getText().toString());
  editor.commit();
  </code></pre>
  
  <p>This is my first non Activity class</p>
  
  <pre><code>private String name;
  private Context mContext;
  
  public PdfConsultantContacts(Context context){
      mContext = context;
  }
  
  public String getName() {
      return name;
  }
  public void setName(String name) {
      this.name = name;
  }
  </code></pre>
  
  <p>And this is my second non Activity class.
      Context mContext; 
      PdfConsultantContacts contact = new PdfConsultantContacts(mContext);</p>
  
  <pre><code>void initContact() {
  SharedPreferences prefs =        mContext.getApplicationContext().
  getSharedPreferences("app_prefs", 0);
  contact.setName(prefs.getString("name", null));
  }
  </code></pre>
  
  <p>When I try to <code>contact.getName();</code> I get always a Nullpointer exception, but I know that the <code>SharedPreference</code> are saved correctly.</p>