title: Android studio if empty field
body: <p>I created a register page and i implemented code to check if the username is empty and if it is to give an error statement but it isn't working . No error message just not doing it's job . I can click the register button and if there is no info in it it still goes into the database . This is the code that isn't working .</p>
  
  <pre><code>if (TextUtils.isEmpty(username)) {
      Log.d(TAG, "Username is empty. Please fill it in .");
  } else {
  }
  </code></pre>
  
  <p>RegisterActivity :</p>
  
  <pre><code>import android.app.AlertDialog;
      import android.content.Intent;
      import android.nfc.Tag;
      import android.os.Bundle;
      import android.support.v7.app.AppCompatActivity;
      import android.text.TextUtils;
      import android.util.Log;
      import android.view.View;
      import android.widget.Button;
      import android.widget.EditText;
      import android.widget.Toast;
  
      import com.android.volley.RequestQueue;
      import com.android.volley.Response;
      import com.android.volley.toolbox.Volley;
  
      import org.json.JSONException;
      import org.json.JSONObject;
  
  public class RegisterActivity extends AppCompatActivity {
  
  private static final String TAG = "LoginActivity";
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_register);
  
      final EditText etUsername = (EditText) findViewById(R.id.etUsername);
      final EditText etPassword = (EditText) findViewById(R.id.etPassword);
      final Button bRegister = (Button) findViewById(R.id.bRegister);
  
      bRegister.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              final String username = etUsername.getText().toString();
              final String password = etPassword.getText().toString();
  
              if (TextUtils.isEmpty(username)) {
                  Log.d(TAG, "Username is empty. Please fill it in .");
              } else {
  
              }
  
              Response.Listener&lt;String&gt; responseListener = new Response.Listener&lt;String&gt;() {
                  @Override
                  public void onResponse(String response) {
                      try {
                          JSONObject jsonResponse = new JSONObject(response);
                          boolean success = jsonResponse.getBoolean("success");
                          if (success) {
                              Intent intent = new   Intent(RegisterActivity.this, LoginActivity.class);
                              RegisterActivity.this.startActivity(intent);
                          } else {
                              AlertDialog.Builder builder = new AlertDialog.Builder(RegisterActivity.this);
                              builder.setMessage("User details already in use")
                                      .setNegativeButton("Retry", null)
                                      .create()
                                      .show();
                          }
                      } catch (JSONException e) {
                          e.printStackTrace();
                      }
  
                  }
              };
              RegisterRequest registerRequest = new RegisterRequest( username, password, responseListener);
              RequestQueue queue =  Volley.newRequestQueue(RegisterActivity.this);
              queue.add(registerRequest);
          }
      });
  }
  }
  </code></pre>