samedi 28 février 2015

Creating a Login in android using SQLite

The scenario is that I want to create a login for my app which uses sqlite, it hasnt got to be secure as its for demonstration purposes only and wont be storing any personal information about real people. But so far I can create an account, but when i try to log in, the trouble starts. I have a method which is supposed to get a password for the email (the email is the parameter) my code so far is this -



public String getSingleEntry1(String email)
{
SQLiteDatabase database = open();
database.beginTransaction();

Cursor cursor=database.query(DataBaseHelper.TABLE_NAME, null, DataBaseHelper.COLUMN_EMAIL + "=?", new String[]{email}, null, null, null);
if(cursor.moveToFirst()) // UserName Not Exist
{
cursor.close();
return "NOT EXIST";
}
cursor.moveToFirst();
String password = cursor.getString(cursor.getColumnIndex(DataBaseHelper.COLUMN_PASSWORD));
cursor.close();
database.setTransactionSuccessful();
database.endTransaction();
close(database);

return password;}


The error happens at String password line. The error is - 02-28 15:11:28.683 11381-11381/com.example.joeliomason.projectme E/AndroidRuntime﹕ FATAL EXCEPTION: main Process: com.example.joeliomason.projectme, PID: 11381 android.database.CursorIndexOutOfBoundsException: Index 0 requested, with a size of 0


I know I have a stupid error somewhere, but I cant figure out where, any help wold be appreciated :)


Aucun commentaire:

Enregistrer un commentaire