title: SharedPreference - Null Pointer Exception
body: <p>I am trying to save something to SharedPreferences using this code below:</p>
  
  <pre><code>public class SignupActivity extends Activity {
  
      String str;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          // TODO Auto-generated method stub
          super.onCreate(savedInstanceState);
          setContentView(R.layout.signup);
  
          str = PreferenceManager.getDefaultSharedPreferences(this).getString(
                  "signedUp", null);
  
          SharedPreferences app_preferences = PreferenceManager
                  .getDefaultSharedPreferences(this);
  
          String text = app_preferences.getString("signedUp", null);
  
          if(str.equals("YES")){
              startActivity(new Intent("com.mobi.job.scout.MyTabActivity"));
          }
  
          markAsSignedUp();
  
      }
  
      public void markAsSignedUp() {
          SharedPreferences.Editor localEditor = PreferenceManager
                  .getDefaultSharedPreferences(getBaseContext()).edit();
          localEditor.putString("signedUp", "YES");
          localEditor.commit();
          Log.d("Signed Up!", ":)");
      }
  
  }
  </code></pre>
  
  <p>I have read and followed some tutorials on the internet but I'm getting the error below.
  This is the logcat:</p>
  
  <pre><code>10-23 01:47:27.061: E/AndroidRuntime(408): FATAL EXCEPTION: main
  10-23 01:47:27.061: E/AndroidRuntime(408): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mobi.job.scout/com.mobi.job.scout.SignupActivity}: java.lang.NullPointerException
  10-23 01:47:27.061: E/AndroidRuntime(408):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
  10-23 01:47:27.061: E/AndroidRuntime(408):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
  10-23 01:47:27.061: E/AndroidRuntime(408):  at android.app.ActivityThread.access$2300(ActivityThread.java:125)
  10-23 01:47:27.061: E/AndroidRuntime(408):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
  10-23 01:47:27.061: E/AndroidRuntime(408):  at android.os.Handler.dispatchMessage(Handler.java:99)
  10-23 01:47:27.061: E/AndroidRuntime(408):  at android.os.Looper.loop(Looper.java:123)
  10-23 01:47:27.061: E/AndroidRuntime(408):  at android.app.ActivityThread.main(ActivityThread.java:4627)
  10-23 01:47:27.061: E/AndroidRuntime(408):  at java.lang.reflect.Method.invokeNative(Native Method)
  10-23 01:47:27.061: E/AndroidRuntime(408):  at java.lang.reflect.Method.invoke(Method.java:521)
  10-23 01:47:27.061: E/AndroidRuntime(408):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
  10-23 01:47:27.061: E/AndroidRuntime(408):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
  10-23 01:47:27.061: E/AndroidRuntime(408):  at dalvik.system.NativeStart.main(Native Method)
  10-23 01:47:27.061: E/AndroidRuntime(408): Caused by: java.lang.NullPointerException
  10-23 01:47:27.061: E/AndroidRuntime(408):  at com.mobi.job.scout.SignupActivity.onCreate(SignupActivity.java:28)
  10-23 01:47:27.061: E/AndroidRuntime(408):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
  10-23 01:47:27.061: E/AndroidRuntime(408):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
  10-23 01:47:27.061: E/AndroidRuntime(408):  ... 11 more
  </code></pre>
  
  <p>Please let me know what is wrong with the code I am using, I always end up getting force close. Thanks</p>