-
Android Login
Hey Guys,
I'm working on an android login activity where one must enter just a username to access the main menu. However I'm getting this error in the log when I try to enter my username.
NOTE :swalsh = username
SQLiteException no such column swalsh while compiling SELECT DISTINCT USERNAME FROM members where USERNAME equals swalsh
The table members defiantly exists and the username is defiantly swalsh.
Here Is my loginactivity
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.login);
db = new MyDB(this);
db.open();
username = (AutoCompleteTextView)findViewById(R.id.txtUsernam e);
password = (AutoCompleteTextView)findViewById(R.id.txtPasswor d);
username.setText(Username);
password.setText(Password);
btnLogin = (Button)findViewById(R.id.btnLogin);
btnLogin.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
try {
readfromDB();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
}
public void readfromDB(){
//save to DB
db.readlogin(username.getText().toString());
db.close();
username.setText("");
// password.setText("");
Toast.makeText(Login.this, "Login Successful!!", Toast.LENGTH_SHORT).show();
Intent i = new Intent(Login.this, MainMenu.class);
startActivity(i);
// if(Username == (Constants.USERNAME) && Password == (Constants.PASSWORD)){
// Toast.makeText(Login.this, "Login Passed!!", Toast.LENGTH_SHORT).show();
// Intent i = new Intent(Login.this, MainMenu.class);
// startActivity(i);
// }
// else{
// Toast.makeText(Login.this, "Login Failed!!", Toast.LENGTH_SHORT).show();
// }
}
}
And this is my Database
public void readlogin(String username) throws SQLException {
Cursor mCursor =
db.query(true, Constants.MEMBERS_TABLE, new String[] {
Constants.USERNAME}, Constants.USERNAME + "=" + username, null,
null, null, null, null);
if (mCursor != null) {
mCursor.moveToFirst();
}
return;
Can anybody tell me what might be wrong on this one thanks
Sean:confused:
-
It was painful like finding a needle in a haystack but i managed to fix it!!!
I was missing quotations around username in this line because it is a string
Constants.USERNAME}, Constants.USERNAME + "=" + username, null,
Thanks :)