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:

publicstaticfinalStringKEY_TRIP_TYPE="trip type";

instead of

publicstaticfinalStringKEY_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:

privatestaticfinalString 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:

publicstaticfinalStringKEY_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 :

publicstaticfinalStringKEY_TRIPID="_id";
publicstaticfinalStringKEY_TITLE="title";
publicstaticfinalStringKEY_DESTINATION="destination";
publicstaticfinalStringKEY_TRIP_TYPE="trip_type";
publicstaticfinalStringKEY_STARTDATE="start_date";
publicstaticfinalStringKEY_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"