title: How to Save Menu item Checked state in SharedPreferences?
body: <p>In my app's Menu i have 2 items, one of them is Checkable and i want to save his state using SharedPreferences. 
  Here is my code:
  <strong>MainActivity</strong><BR></p>
  
  <pre><code> MenuItem bubu1;
   boolean isChecked;
  
   @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main_activity);
  
   bubu1.setChecked(getFromSP("cec1"));
    }
  
  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
      getMenuInflater().inflate(R.menu.main, menu);
      return true;
  }
  
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
      switch (item.getItemId()) {
          case R.id.action_rate_us:
  
              break;
          case R.id.action_enab:
              saveInSp("cec1",isChecked);
              if (bubu1.isChecked()) {
                  bubu1.setChecked(false);
  
              }else{
  
                  bubu1.setChecked(true);
              }
              return true;
          default:
              break;
      }
  
      return super.onOptionsItemSelected(item);
  }
  
  private boolean getFromSP(String key){
      SharedPreferences preferences = getApplicationContext().getSharedPreferences("PROJECT_NAME", android.content.Context.MODE_PRIVATE);
      return preferences.getBoolean(key, false);
  }
  
  private void saveInSp(String key,boolean value){
      SharedPreferences preferences = getApplicationContext().getSharedPreferences("PROJECT_NAME", android.content.Context.MODE_PRIVATE);
      SharedPreferences.Editor editor = preferences.edit();
      editor.putBoolean(key, value);
      editor.commit();
  }
  </code></pre>
  
  <p><BR><strong>Menu xml</strong><BR></p>
  
  <pre><code> &lt;menu xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:app="http://schemas.android.com/apk/res-auto"&gt;
  &lt;item android:id="@+id/action_enab"
      android:title="@string/enab"
      android:orderInCategory="100"
      android:showAsAction="always"
      android:checkable="true"
      android:checked="false"
      /&gt;
  
  &lt;item
      android:id="@+id/action_rate_us"
      android:orderInCategory="100"
      android:showAsAction="never"
      android:title="@string/action_rate_us"/&gt;
  </code></pre>
  
  <p></p>
  
  <p><BR><strong>And here is the error i get:</strong><BR></p>
  
  <pre><code> FATAL EXCEPTION: main
   Process: dia.it.solutions.lagcleaner, PID: 6143
   java.lang.RuntimeException: Unable to start activity ComponentInfo{dia.it.solutions.lagcleaner/dia.it.solutions.lagcleaner.MainActivity}: java.lang.NullPointerException
   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2447)
   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2507)
   at android.app.ActivityThread.access$900(ActivityThread.java:172)
   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1308)
   at android.os.Handler.dispatchMessage(Handler.java:102)
   at android.os.Looper.loop(Looper.java:146)
   at android.app.ActivityThread.main(ActivityThread.java:5692)
   at java.lang.reflect.Method.invokeNative(Native Method)
   at java.lang.reflect.Method.invoke(Method.java:515)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1291)
  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1107)
  at dalvik.system.NativeStart.main(Native Method)
  Caused by: java.lang.NullPointerException
  at dia.it.solutions.lagcleaner.MainActivity.onCreate(MainActivity.java:95)
  at android.app.Activity.performCreate(Activity.java:5541)
  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093)
  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2411)
   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2507) 
    at android.app.ActivityThread.access$900(ActivityThread.java:172) 
     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1308) 
      at android.os.Handler.dispatchMessage(Handler.java:102) 
     at android.os.Looper.loop(Looper.java:146) 
     at android.app.ActivityThread.main(ActivityThread.java:5692) 
     at java.lang.reflect.Method.invokeNative(Native Method) 
  </code></pre>
  
  <p><BR>From the error, i understand that the app crashes because of the line 95 from MainActivity and here is the 95 line:<BR></p>
  
  <blockquote>
    <p>bubu1.setChecked(getFromSP("cec1"));</p>
  </blockquote>
  
  <p><BR>Any ideas why this is happening?</p>