title: Having a difficult time making a static method which utilizes non-static methods
body: <p>I'm about 6 weeks into learning Java and still struggling with implementing static methods (thought I really understood it, but this proved me wrong!).</p>
  
  <p>I'm trying to make the value of a locally stored key-value pair available publicly. Here's my initial code:</p>
  
  <pre><code>public class Settings extends Activity implements OnClickListener {
          public Settings(TextView loginText, TextView passwdText) {
      super();
      this.loginText = loginText;
      this.passwdText = passwdText;
  }
  
  public static String getDriverNum() {
      SharedPreferences sp = getSharedPreferences(DELEX_SP, MODE_PRIVATE); &lt;---ERROR
      String Login = sp.getString("KeyLgn", "No Login Found");
      return Login;
  }
  </code></pre>
  
  <p>Of course, I get an error "Cannot make a static reference to the non-static method getSharedPreferences(String, int) from the type ContextWrapper", so I try to wrap the non-static method in my own public method, as a similar StackOverflow <a href="https://stackoverflow.com/questions/926822/java-non-static-variable-cannot-be-referenced-from-a-static-context-error">answer</a> indicated:</p>
  
  <pre><code>public class Settings extends Activity implements OnClickListener {
  public Settings(TextView loginText, TextView passwdText) {
      super();
      this.loginText = loginText;
      this.passwdText = passwdText;
  }
  
  public static String getDriverNum() {
      String Login = getSharedPref().getString("KeyLgn", "No Login Found"); &lt;-- SAME ERROR
      return Login;
  }
  
  public  SharedPreferences getSharedPref() {
      SharedPreferences sp = getSharedPreferences(DELEX_SP, MODE_PRIVATE);
      return sp;
  }
  </code></pre>
  
  <p>But this just caused the same error as I haven't resolved the call to the non-static <em>getSharedPreferences</em> method. What's the best way to resolve this? Is it to create a class that wraps <em>getSharedPreferences</em> instead? </p>
  
  <p>Thanks for your patience while I struggle with static nomenclature.</p>