1

I am trying to configure a simple SQLiteOpenHelper, and getting an error while executing. android.database.sqlite.SQLiteException: table people_table has no column named Minutes (code 1): , while compiling: INSERT INTO people_table(Minutes,Hour) VALUES (?,?) I canot figure out what is the problem?

  package radiofm.arabel;

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


public class DatabaseHelper extends SQLiteOpenHelper {

    private static final String TAG = "DatabaseHelper";

    private static final String TABLE_NAME = "people_table";
    private static final String COL1 = "ID";
    private static final String COL2 = "Hour";
    private static final String COL3 = "Minutes";



    public DatabaseHelper(Context context) {
        super(context, TABLE_NAME, null, 1);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {

        String createTable = "CREATE TABLE " + TABLE_NAME + " (" +

                COL1 + "ID INTEGER PRIMARY KEY AUTOINCREMENT," +

                COL2 + "TEXT," +

                COL3 + "TEXT "  +

                ");";

        db.execSQL(createTable);
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int i, int i1) {
        db.execSQL("DROP IF TABLE EXISTS " + TABLE_NAME);
        onCreate(db);
    }

    public boolean addData(String item1,String item2) {
        SQLiteDatabase db = this.getWritableDatabase();
        ContentValues contentValues = new ContentValues();
        contentValues.put(COL2, item1);
        contentValues.put(COL3, item2);

        Log.d(TAG, "addData: Adding " + item1 + " to " + TABLE_NAME);


        long result = db.insert(TABLE_NAME, null, contentValues);

        //if date as inserted incorrectly it will return -1
        if (result == -1) {
            return false;
        } else {
            return true;
        }
    }


}
0

2 Answers 2

1

You forgot the space when creating the table. Your column is named MinutesTEXT right now.

It is not an error in itself because you do not have to specify the column type in SQLite.

Reference

To fix it, make sure you delete the current database and replace your Create table query with this.

String createTable = "CREATE TABLE " + TABLE_NAME + " (" +

                COL1 + " INTEGER PRIMARY KEY AUTOINCREMENT," +

                COL2 + " TEXT," +

                COL3 + " TEXT "  +

                ");";
Sign up to request clarification or add additional context in comments.

5 Comments

what do u mean ?
What do i mean by what?
where did i forget the space ?
Between the column name and the type when you concatenate.
Are you sure you deleted the database. In android, if the database is already present, onCreate will not be called and so your old name will still be there. To do it you could force an update by changing the version number
0

Your onCreate seems to be missing spaces on your SQL column definition. Also, your id columns must to be defined as _id.

Try this.

 private static final String COL1 = "_id";

And

@Override
    public void onCreate(SQLiteDatabase db) {

        String createTable = "CREATE TABLE " + TABLE_NAME + " (" +

                COL1 + " INTEGER PRIMARY KEY AUTOINCREMENT, " +

                COL2 + " TEXT, " +

                COL3 + " TEXT "  +

                ");";

        db.execSQL(createTable);
    }

4 Comments

Can you debug and paste createTable value here, please?
CREATE TABLE people_table (ID ID INTEGER PRIMARY KEY AUTOINCREMENT,Hour TEXT,Minutes TEXT );
@mohammadalsaleh see my editing and let me know if it solves.
ID ID INTEGER... seems to be wrong. I edited the answered. See if it works

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.