Why does my application crash when I correct a spelling error in my SQL table name?

advertisements
 private static final String TABLE_USERS = "Registerd_Accounts";

when i change it to this private static final String TABLE_USERS = "Registered_Accounts";

it crashed when i press a button or anything that uses the database.When i change it back to the misspelled it works.However "Registerd_Accounts" is only used in the handler so whats up? enter code here.

 package com.set.ultimax.login;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class DatabaseHandler extends SQLiteOpenHelper {

// All Static variables
// Database Version
private static final int DATABASE_VERSION = 1;

// Database Name
private static final String DATABASE_NAME = "All_Accounts";

private static final String TABLE_USERS = "Registered_Accounts";

// Contacts Table Columns names
private static final String KEY_ID = "id";
private static final String KEY_USERS = "userName";
private static final String KEY_PASS = "passWord";

public DatabaseHandler(Context context) {
    super(context, DATABASE_NAME, null, DATABASE_VERSION);
}

// Creating Tables
@Override
public void onCreate(SQLiteDatabase db) {
    String CREATE_ACCOUNT_TABLE = "CREATE TABLE " + TABLE_USERS + "("
            + KEY_ID + " INTEGER PRIMARY KEY," + KEY_USERS + " TEXT,"
            + KEY_PASS + " TEXT" + ")";
    db.execSQL(CREATE_ACCOUNT_TABLE);
}

// Upgrading database
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    // Drop older table if existed
    db.execSQL("DROP TABLE IF EXISTS " + TABLE_USERS);
    onCreate(db);// Create tables again
}

// Adding new User
void addUsers(Users users) {
    SQLiteDatabase db = this.getWritableDatabase();

    ContentValues values = new ContentValues();
    values.put(KEY_USERS, users.getUser()); // User Name
    values.put(KEY_PASS, users.getPassword()); // Password

    // Inserting Row
    db.insert(TABLE_USERS, null, values);
    db.close(); // Closing database connection
}
public void deleteAll() //Deletes all data in the database
{
    SQLiteDatabase db = this.getWritableDatabase();
    db.delete(TABLE_USERS,null,null);
}

public boolean validateUser(String username, String password){
    Cursor c = getReadableDatabase().rawQuery(
            "SELECT * FROM " + TABLE_USERS + " WHERE "
                    + KEY_USERS + "='" + username +"'AND "+KEY_PASS+"='"+password+"'" ,  null);
    if (c.getCount() > 0) {
        return true;
    }
    else{return false;}

}
public boolean sameUser(String username){
    Cursor c = getReadableDatabase().rawQuery(
            "SELECT * FROM " + TABLE_USERS + " WHERE "
                    + KEY_USERS + "='" + username  + "'" ,  null);
    if (c.getCount() > 0) {
        return true;
    }
    else{return false;}
}

}

Here is my accessor methods methods

 package com.set.ultimax.login;

  public class Users {

//private variables
int _id; // Just to have it.
String _userName;
String _passWord;

// Empty constructor
public Users(){

}
// constructor
public Users(String userName, String _passWord){
    this._userName = userName;
    this._passWord = _passWord;
}
// getting User
public String getUser(){
    return this._userName;
}

// getting Password
public String getPassword(){
    return this._passWord;
}
}


You should uninstall the application from your device and again install and check it. It may be helpful for you because when we install the application then our application creates the local database and database table also. So,when you installed your then your local database has been created with misspelled table name and your application try to find the correct spelling table.