public static final String TAG = DBHelper.class.getSimpleName(); public static final int DATEBASE_VERSION = 1; public static final String DATEBASE_NAME = "ContactDB"; public static final String TABLE_CONTACT = "Contact"; public static final String KEY_ID = "ID"; public static final String KEY_NAME = "Name"; public static final String KEY_LOGIN = "Login"; public static final String KEY_PASS = "Pass"; public static int countUser = 0; public DBHelper(Context context) { super(context, DATEBASE_NAME, null, DATEBASE_VERSION); } public static final String CREATE_TABLE_USERS = "CREATE TABLE " + TABLE_CONTACT + " ( " + KEY_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " + KEY_NAME + " TEXT, " + KEY_LOGIN + " TEXT, " + KEY_PASS + " TEXT);"; @Override public void onCreate(SQLiteDatabase db) { db.execSQL(CREATE_TABLE_USERS); } @Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { db.execSQL("DROP TABLE IF EXISTS " + TABLE_CONTACT); onCreate(db); } @Override public void addContact(Contact contact) { SQLiteDatabase db = this.getWritableDatabase(); ContentValues value = new ContentValues(); value.put(KEY_NAME, contact.getName()); value.put(KEY_LOGIN, contact.getLogin()); value.put(KEY_PASS, contact.getPass()); Long id = db.insert(TABLE_CONTACT, null, value); db.close(); Log.d(TAG, "user inserted" + id); countUser++; } 

Mistake:

 E/SQLiteLog: (1) table Contact has no column named Name E/SQLiteDatabase: Error inserting Login=fediafedia@ Name=fedia Pass=ihgldihgld android.database.sqlite.SQLiteException: table Contact has no column named Name (code 1): , while compiling: INSERT INTO Contact(Login,Name,Pass) VALUES (?,?,?) 

    2 answers 2

    Most likely you created a table, and then added some other fields in the code, but did not change the version of the database.

    Try increasing the version of DATEBASE_VERSION - in this case, when connecting to the database, the onUpgrade(...) method will be called, which will delete the old table and create a new one (the data stored in the table will be lost ).

      As a version, most likely SQLite swears at the name of the Name field. The SQLite tutorial says the following:

      For most SQL code, you can never use it.

      Well, that is, as the name of your objects / entities, it is better not to use any English words at all.

      I would rename:

       public static final String KEY_NAME = "field_name"; 

      Well, at the same time, in order not to get up 2 times in Android, the key field should be called _ID by default (with the leading underscore character)