title: nullpointerexception getSharedPreferences
body: <p>I am trying to save some preferences within my android app. But when I am trying to get a sharedpreference I am getting a nullpointerexception. This is the error:</p>
  
  <pre><code>04-25 13:58:44.814: W/System.err(22795): java.lang.NullPointerException
  04-25 13:58:44.824: W/System.err(22795):    at com.koeriers.standaard.SharedPreferences.setData(SharedPreferences.java:27)
  04-25 13:58:44.829: W/System.err(22795):    at com.koeriers.standaard.actLogin.onCreate(actLogin.java:79)
  04-25 13:58:44.834: W/System.err(22795):    at android.app.Activity.performCreate(Activity.java:5206)
  04-25 13:58:44.839: W/System.err(22795):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
  04-25 13:58:44.844: W/System.err(22795):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2074)
  04-25 13:58:44.849: W/System.err(22795):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2135)
  04-25 13:58:44.854: W/System.err(22795):    at android.app.ActivityThread.access$700(ActivityThread.java:140)
  04-25 13:58:44.859: W/System.err(22795):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1237)
  04-25 13:58:44.864: W/System.err(22795):    at android.os.Handler.dispatchMessage(Handler.java:99)
  04-25 13:58:44.869: W/System.err(22795):    at android.os.Looper.loop(Looper.java:137)
  04-25 13:58:44.874: W/System.err(22795):    at android.app.ActivityThread.main(ActivityThread.java:4921)
  04-25 13:58:44.874: W/System.err(22795):    at java.lang.reflect.Method.invokeNative(Native Method)
  04-25 13:58:44.879: W/System.err(22795):    at java.lang.reflect.Method.invoke(Method.java:511)
  04-25 13:58:44.884: W/System.err(22795):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1027)
  04-25 13:58:44.889: W/System.err(22795):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:794)
  04-25 13:58:44.894: W/System.err(22795):    at dalvik.system.NativeStart.main(Native Method)
  </code></pre>
  
  <p>This is my SharedPreferences class:</p>
  
  <pre><code>package com.myapp.standaard;
  
  import android.os.Bundle;
  import android.preference.PreferenceActivity;
  import android.widget.EditText;
  
  public class SharedPreferences extends PreferenceActivity {
  
  public static String GUID = "8BB4894B-92F7-45AF-9A40-B99D7A06A506";
  public static String LicenseKey = "letmein";
  
  EditText etLicense;
  android.content.SharedPreferences sharedPrefs;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      try {
          addPreferencesFromResource(R.xml.preferences);
          etLicense = (EditText) findViewById(R.id.etLicense);
      } catch (Exception e) {
          e.printStackTrace();
      }
  }
  
  public Boolean setData(String setPreference, String setValue) {
      android.content.SharedPreferences.Editor editor = sharedPrefs.edit();
      editor.putString(setPreference, setValue);
      editor.commit();
      return true;
  }
  
  public String getData(String getPreference, String errorMessage) {
      sharedPrefs = getSharedPreferences(getPreference, MODE_PRIVATE);
      String returnData = sharedPrefs.getString(getPreference, errorMessage);
      return returnData;
  }
  }
  </code></pre>
  
  <p>and this is the place in my Activity where I am trying to retrieve the value from my preference:</p>
  
  <pre><code>try{
  
          SharedPreferences sp = new SharedPreferences();
          licentie = sp.getData("LicenseKey", "Error loading license");
      } catch (Exception e){
          e.printStackTrace();
          licentie = "";
      }
  </code></pre>