Skip to content Skip to sidebar Skip to footer

SQLite Error When Trying To Insert Values

I'm new to android and trying to learn how to create and insert stuff into a database. I managed to create it and the app runs but I get this error whenever I try to insert stuff i

Solution 1:

public static final String KEY_TRIP_TYPE = "trip type";

instead of

public static final String KEY_TRIP_TYPE = "trip_type";

because space is not allow in database field in sqlite.

and if you already created database table in assets db folder then don't create it in java file.and if you do not create table externally then use this:

private static final String DATABASE_CREATE = 
      "create table if not exists trips (trip_id integer primary key   autoincrement, " 
    + "title VARCHAR not null, destination VARCHAR not null, triptype VARCHAR not null,"
    + " startdate VARCHAR, enddate VARCHAR);

if this ans is useful to you,please vote up.


Solution 2:

It seems you have spaces in your db column names, use '_' instead:

public static final String KEY_TRIP_TYPE = "trip_type";

Solution 3:

Your column name trip type has a space inbetween it. It means you are going to have to use ` around it. E.g. `trip type`. Or better yet, instead of spaces, replace the spaces with underscores.

E.g. public static final String KEY_TRIP_TYPE = "trip_type";

You can do this with your other columns as well.

Note: As you have changed the column names, you may have toclear data, or uninstall then reinstall the app.


Solution 4:

change this :

public static final String KEY_TRIPID = "_id";
public static final String KEY_TITLE = "title";
public static final String KEY_DESTINATION = "destination";
public static final String KEY_TRIP_TYPE = "trip_type";
public static final String KEY_STARTDATE = "start_date";
public static final String KEY_ENDDATE = "end_date";

for more take look here. And also you need to update the table structure using database version upgrade.


Post a Comment for "SQLite Error When Trying To Insert Values"