title: java.lang.StringIndexOutOfBoundsException error
body: <p>I am trying to make a local validation. Every combination you enter in editText1 (for example abc) should be converted to numbers (a=1, b=2, c=3). The text in editText2 should match abc converted to numbers (123). If this is true: start the new activity. else: display a 'login failed' textview.</p>
  
  <pre><code> public class Login extends Activity {
  
  @SuppressLint("NewApi")
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setTitle(R.string.login);
      setContentView(R.layout.home_login);
      Button btn = (Button) findViewById(R.id.loginButton2);
  
      EditText email_text = (EditText) findViewById(R.id.editText1);
      EditText code_text = (EditText) findViewById(R.id.editText2);
      final String userEmail = email_text.getText().toString(); 
      final String userCode = code_text.getText().toString(); 
      String x = "";
  
      for (int i = 0; i &lt;= 2; i++) {
          x += getNumber(userEmail.charAt(i)); 
      }
      final int validCode = Integer.parseInt(x);
  
      btn.setOnClickListener(new OnClickListener() {
  
          @SuppressLint("ResourceAsColor")
          @Override
          public void onClick(View v) {
              if (userCode.equals(validCode)) {
                  Intent intent = new Intent(Login.this, Home.class);
                  startActivity(intent);
              } else {
                  TextView view = (TextView) findViewById(R.id.loginfailed);
                  view.setVisibility(View.VISIBLE);
                  editText2.setText("");
              }
          }
  
      });
  
  }
  
  private int getNumber(Character c) {
      return "abdcefghijklmnopqrstuvwxyz".indexOf(c) + 1;
  }
  </code></pre>
  
  <p>However, when I run my app it crashes immediately and the following error raises: </p>
  
  <pre><code>FATAL EXCEPTION:main 
  java.lang.RuntimeException: Unable to start activity ComponentInfo {...}:
  java.lang.StringIndexOutOfBoundsException: length=0; index=0
  </code></pre>
  
  <p>how do i fix this??</p>