title: Java - Checking if int is empty
body: <p>I'm trying to do field validation for an int in android studio. The code for the field is as follows;</p>
  
  <pre><code>public class Register extends ActionBarActivity implements View.OnClickListener {
  
      EditText etName, etAge, etUsername, etPassword;
      Button bRegister;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_register);
  
          etName = (EditText) findViewById(R.id.etName);
          etAge = (EditText) findViewById(R.id.etAge);
          etUsername = (EditText) findViewById(R.id.etUsername);
          etPassword = (EditText) findViewById(R.id.etPassword);
          bRegister = (Button) findViewById(R.id.bRegister);
  
          bRegister.setOnClickListener(this);
      }
  
      @Override
      public void onClick(View v) {
          switch (v.getId()) {
              case R.id.bRegister:
                  String name = etName.getText().toString();
                  String username = etUsername.getText().toString();
                  String password = etPassword.getText().toString();
                  String ageText = etAge.getText().toString();
                  if(! TextUtils.isEmpty(ageText)) {
                      int age = Integer.parseInt(ageText);
                  }
  
                  if(name.length()==0)
                  {
                      etName.requestFocus();
                      etName.setError("Please don't leave the name field empty.");
                  }else if(username.length()==0)
                  {
                      etUsername.requestFocus();
                      etUsername.setError("Please don't leave the username field empty.");
                  }else if(password.length()==0)
                  {
                      etPassword.requestFocus();
                      etPassword.setError("Please don't leave the password field empty.");
                  }/*else if(age == null)
                  {
                      etAge.requestFocus();
                      etAge.setError("Please don't leave the age field empty.");
                  }*/
                  else if(!name.matches("[a-zA-Z]"))
                  {
                      etName.requestFocus();
                      etName.setError("Please only use alphabetic characters");
                  }else{
                      User user = new User(name, age, username, password);
                      registerUser(user);
                  }
  
  
                  break;
          }
      }
  
      private void registerUser(User user) {
          ServerRequest serverRequest = new ServerRequest(this);
          serverRequest.storeUserDataInBackground(user, new GetUserCallback() {
              @Override
              public void done(User returnedUser) {
                  Intent loginIntent = new Intent(Register.this, Login.class);
                  startActivity(loginIntent);
              }
          });
      }
  }
  </code></pre>
  
  <p>But I can't get the int age validated, it keps giving me this error;</p>
  
  <blockquote>
    <p>java.lang.NumberFormatException: Invalid int: ""</p>
  </blockquote>
  
  <p>User class</p>
  
  <pre><code>public class User {
      String name, username, password;
      int age;
  
      public User(String name, int age, String username, String password) {
          this.name = name;
          this.age = age;
          this.username = username;
          this.password = password;
      }
  </code></pre>