title: Android Studio Shared Preference Application Stopped Working
body: <p>My mobile application stopped working after I added the checking for ip section in my onCreate function to make registered users bypass the login screen. This might have something to do with the variable declarations but I'm still not sure what's going on.</p>
  
  <pre><code>private EditText etUsername;
  private EditText etPassword;
  private EditText etIpAddress;
  private Button btnLogin;
  
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_login);
  
      String username = etUsername.toString();
      String password = etPassword.toString();
      String ipAddress = etIpAddress.toString();
  
      SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(LoginActivity.this);
      if (sharedPreferences.contains("ip")) {
          performLogin(username, password, sharedPreferences.getString("ip", ipAddress));
      }
  
      // declaring variebles
      etUsername = (EditText)findViewById(R.id.etUsername);
      etPassword= (EditText)findViewById(R.id.etPassword);
      btnLogin = (Button)findViewById(R.id.btnLogin);
      etIpAddress = (EditText) findViewById(R.id.etIpAddress);
  
      // setting up things for login button
      btnLogin.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
  
              String ipAddress = etIpAddress.getText().toString();
  
              SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(LoginActivity.this);
  
              sharedPreferences.edit()
                      .putString("ip", ipAddress)
                      .apply();
  
              String username = etUsername.getText().toString().trim();
              String password = etPassword.getText().toString().trim();
  
              performLogin(username, password, ipAddress);
          }
      });
  }
  
  private void performLogin(String username, String password, String ipAddress) {
      try {
          Device.login(username, password, ipAddress, this);
      } catch (JSONException e) {
          onLoginFailure(e);
      }
  }
  </code></pre>
  
  <p>Logcat:</p>
  
  <pre><code>06-06 16:40:11.408 4000-4000/com.itemlocator.findit E/AndroidRuntime: FATAL EXCEPTION: main
                                                                        Process: com.itemlocator.findit, PID: 4000
                                                                        java.lang.RuntimeException: Unable to start activity ComponentInfo{com.itemlocator.findit/com.itemlocator.findit.LoginActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.widget.EditText.toString()' on a null object reference
                                                                            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
                                                                            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
                                                                            at android.app.ActivityThread.-wrap11(ActivityThread.java)
                                                                            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
                                                                            at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                            at android.os.Looper.loop(Looper.java:148)
                                                                            at android.app.ActivityThread.main(ActivityThread.java:5417)
                                                                            at java.lang.reflect.Method.invoke(Native Method)
                                                                            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
                                                                            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
                                                                         Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.widget.EditText.toString()' on a null object reference
                                                                            at com.itemlocator.findit.LoginActivity.onCreate(LoginActivity.java:32)
                                                                            at android.app.Activity.performCreate(Activity.java:6237)
                                                                            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
                                                                            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
                                                                            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
                                                                            at android.app.ActivityThread.-wrap11(ActivityThread.java) 
                                                                            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
                                                                            at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                            at android.os.Looper.loop(Looper.java:148) 
                                                                            at android.app.ActivityThread.main(ActivityThread.java:5417) 
                                                                            at java.lang.reflect.Method.invoke(Native Method) 
                                                                            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
                                                                            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
  </code></pre>