0

I got this error:

10-08 22:23:06.635: E/SQLiteLog(20613): (1) table mytable has no column named GPS
10-08 22:23:06.645: E/SQLiteDatabase(20613): Error inserting AppName=Ster-Kinekor GPS=false Time=22:23:6 Network=true Date=2014/10/08
10-08 22:23:06.645: E/SQLiteDatabase(20613): android.database.sqlite.SQLiteException: table mytable has no column named GPS (code 1): , while compiling: INSERT INTO mytable(AppName,GPS,Time,Network,Date) VALUES (?,?,?,?,?)

I have checked for all the normal silly mistakes people make to get this error, pretty sure I don't have a comma or spacing wrong. Please help me find the error, really appreciate any assistance

Here's the relevant code:

public static final String KEY_ROWID = "id";
public static final String KEY_AppName = "AppName";
public static final String KEY_Date = "Date";
public static final String KEY_Time = "Time";
public static final String KEY_Gps = "GPS";
public static final String KEY_Network = "Network";

... ... ...

public void onCreate(SQLiteDatabase arg0) {

    try{
        arg0.execSQL("create table if not exists mytable ("
                + "id integer primary key autoincrement, "
                + KEY_AppName+" text not null," 
                + KEY_Date+" text,"
                + KEY_Time+ " text," 
                + KEY_Gps+" text,"
                + KEY_Network+" text"
                +");");

    } catch (Exception e){
        e.printStackTrace();
    }
}


public void insertRecord(LocationUsageDB lb)
    {
        SQLiteDatabase db = this.getWritableDatabase();
        ContentValues initialValues = new ContentValues();//
        initialValues.put(KEY_AppName, lb.AppName); //just do the same for any other columns 
        initialValues.put(KEY_Date, lb.Date);
        initialValues.put(KEY_Time, lb.Time);
        initialValues.put(KEY_Gps, lb.Gps);
        initialValues.put(KEY_Network, lb.Network);

        db.insert(TABLE_NAME, null, initialValues);
        db.close();
    }

And I send values here:

mydb.insertRecord(new LocationUsageDB(foregroundTaskAppName, date, t.hour+":"+t.minute+":"+t.second, "false", "true"  ));
cfl
  • 929
  • 1
  • 13
  • 33
  • 1
    Uninstall your app so that `onCreate()` is run again and remove the `catch` in `onCreate()`. http://stackoverflow.com/questions/21881992/when-is-sqliteopenhelper-oncreate-onupgrade-run – laalto Oct 08 '14 at 20:45
  • Your awesome, thanks alot! Its working now. – cfl Oct 08 '14 at 20:56

0 Answers0