Register not able to be done due to error checking in the if..else statement
<p>I got problem with register. I use an if-else statement to check whether the user left any blank. If there is any blank, an error message will appear. The problem is, even with no blanks, all filled up, the error message still appears and thus prevents user from registering. I can't find any error. </p>

<p>Please help me spot my error.</p>

<pre><code>package log1.log2;


import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;



public class Login extends Activity {


 DBAdapter db = new DBAdapter(this);
/** Called when the activity is first created. */

 private EditText etUsername;
 private EditText etPassword;
 private Button btnLogin;
 private Button btnRegister;
 private TextView lblResult;

    @Override

    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.main);

        // Get the EditText and Button References
        etUsername = (EditText)findViewById(R.id.usernametxt);
        etPassword = (EditText)findViewById(R.id.passwordtxt);
        btnLogin = (Button)findViewById(R.id.btnLogin);
        btnRegister = (Button)findViewById(R.id.btnRegister);
        lblResult = (TextView)findViewById(R.id.msglbl);

        //Cursor c = (Cursor) db.getAllTitles();

        //Button btnArrival = (Button) findViewById(R.id.btnRegister);
     //btnArrival.setOnClickListener(this);


    // Set Click Listener

        btnRegister.setOnClickListener(new OnClickListener() {
         @Override
         public void onClick(View v) {
          Intent intent=new Intent(Login.this,Register.class);
            startActivity(intent);

         }
        });

    btnLogin.setOnClickListener(new OnClickListener() {
 @Override
 public void onClick(View v) 
 {
  db.open();
  Cursor c = (Cursor) db.getAllUser();
  c.moveToFirst();
  // Check Login
  String username = etUsername.getText().toString();
  String password = etPassword.getText().toString();

  if(username.equals("") || password.equals(""))
  {
   Context context = getApplicationContext();
   int duration = Toast.LENGTH_LONG;
   Toast toast = Toast.makeText(context, "FILL IN ALL FIELDS", duration);
   toast.show();

  }
  else
  {
   if(username.equals(c.getString(1)))
   {
    if(password.equals(c.getString(2)))
    {
     Context context = getApplicationContext();
     int duration = Toast.LENGTH_LONG;
     Toast toast = Toast.makeText(context, "LOGIN SUCCESS", duration);
     toast.show();

     long id;
                 id = db.insertTransaction(
      new String(etUsername.getText().toString()));

     Intent intent=new Intent(Login.this,Test.class);
        startActivity(intent);

    }
    else
    {
     Context context = getApplicationContext();
     int duration = Toast.LENGTH_LONG;
     Toast toast = Toast.makeText(context, "LOGIN FAIL", duration);
     toast.show();
    }
   }
   else
   {
    Context context = getApplicationContext();
    int duration = Toast.LENGTH_LONG;
    Toast toast = Toast.makeText(context, "LOGIN FAIL", duration);
    toast.show();
   }
  }
  db.close();
 }
});  

}

}
</code></pre>

<p>Thank you very much.</p>
