title: How to keep Spinner's Selected values after restarting application
body: <p>the question is quite obvious but still nothing worked for me. In my application i'm selecting value from spinner and wanna to let spinner to show selected value after restarting application. to store spinner value i'm using <code>shared preferences</code> But when restarts application logcat shows <code>null pointer error</code>. Here's code</p>
  
  <pre><code>String options[]={"-Select-", "Domino's","Pizza Hut", "Pizza Bite"}; 
  Spinner spin;
  int formatposition;
  fSpinner = (Spinner)findViewById(R.id.fSpinner);
              ArrayAdapter&lt;String&gt; adp = new ArrayAdapter&lt;String&gt; (MainActivity.this,android.R.layout.simple_spinner_dropdown_item,options);
              fSpinner.setAdapter(adp);
  </code></pre>
  
  <p>To store spinner selected value:</p>
  
  <pre><code>Editor editee = preferences.edit();
                      editee.putInt("lastindex", spin.getSelectedItemPosition());
                      editee.commit();
  </code></pre>
  
  <p>To restore shared preferences when application restarts</p>
  
  <pre><code>protected void onCreate(Bundle savedInstanceState)                  //onCreate is called when the activity is starting
  {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);
      context=this;
      listViewSMS=(ListView)findViewById(R.id.lvSMS);                                 //view that shows items in a vertically scrolling list
      btnaddnew = (Button)findViewById(R.id.btnaddnew);
      btnaddnew.setOnClickListener(this);
     formatposition = preferences.getInt("lastindex", 0);
      spin.setSelection(formatposition);
  }
  </code></pre>