title: SharedPreferences not working ("Cannot resolve method 'getPreferences' ")
body: <p>Hi I'm currently trying to save a simple integer value from an EditText to sharedPreferences so that I can access it within any activity. I've tried following the google tutorials but I was unable to make it work. I ended up getting the error message "Cannot resolve method 'getPreferences' ". I realize that there have been other threads about sharedPreferences but I cannot seem to make sense of them. </p>
  
  <p>Also, if you can help me find a better way than my catch statement to avoid the NumberFormatException, please let me know. Thanks again!Any help is much appreciated!</p>
  
  <p>Java</p>
  
  <pre><code>import android.content.Context;
  import android.content.SharedPreferences;
  import android.preference.PreferenceManager;
  import android.support.v7.app.AppCompatActivity;
  import android.os.Bundle;
  import android.view.View;
  import android.widget.Button;
  import android.widget.EditText;
  import android.widget.TextView;
  
  import static com.managergmail.time.finite.finitemanager02.R.id.textViewTest;
  
  
  public class ExamPrepHome extends AppCompatActivity {
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_exam_prep_home);
  
      Button buttonSaveNumberOfExams = (Button) findViewById(R.id.buttonSaveNumberOfExams);
  
  
      try{
             final  EditText numberOfExamsInput = (EditText) findViewById(R.id.numberOfExamsInput);
             final int numberOfExamsValue = Integer.valueOf(numberOfExamsInput.getText().toString());
  
  
             buttonSaveNumberOfExams.setOnClickListener(new View.OnClickListener() {
                      @Override
                      public void onClick(View v) {
                          SharedPreferences sharedPref = this.getPreferences(Context.MODE_PRIVATE);
                          SharedPreferences.Editor editor = sharedPref.edit();
                          editor.putInt(getString(R.string.saved_number_of_exams), numberOfExamsValue);
                          editor.commit();
                      }
  
                  });
  
             }catch(NumberFormatException ex){
  
                  System.out.println("Value at TextView is not a valid integer");
  
              }
  
  
  
  }
  </code></pre>
  
  <p>}</p>