Reputation: 101
im searching for about 2hours(google,youtube and here) what am doing wrong but cant understand what is it. im getting this error in the log
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.cage.roll.midleprojectfinal/com.cage.roll.midleprojectfinal.MainActivity}: android.database.sqlite.SQLiteException: near ")": syntax error (code 1): , while compiling: CREATE TABLE IF NOT EXISTS tblmovies(movieId INTEGER PRIMARY KEY AUTOINCREMENT,movieName VARCHAR,movieSummery VARCHAR,imageURL VARCHAR,);
Caused by: android.database.sqlite.SQLiteException: near ")": syntax error (code 1): , while compiling: CREATE TABLE IF NOT EXISTS tblmovies(movieId INTEGER PRIMARY KEY AUTOINCREMENT,movieName VARCHAR,movieSummery VARCHAR,imageURL VARCHAR,);
and from what i found so far i am not using any sqlite reserved words and the spaces in the create table are ok.... this my code:
public class MoviesOpenHelper extends SQLiteOpenHelper {
SQLiteDatabase database;
//DB properties
public static final String DATABASENAME="movies.db";
public static final String TABLE_MOVIES="tblmovies";
public static final int DATABASEVERSION=1;
//DB members in static mode to gain access to all APP classes
public static final String COLUMN_ID="movieId";
public static final String COLUMN_MOVIENAME="movieName";
public static final String COLUMN_MOVIESUMMERY="movieSummery";
public static final String COLUMN_IMAGEURL="imageURL";
//Creating the DB table
private static final String CREATE_TABLE_MOVIES =" CREATE TABLE IF NOT EXISTS " + TABLE_MOVIES + " ("
+ COLUMN_ID + " INTEGER PRIMARY KEY AUTOINCREMENT,"
+ COLUMN_MOVIENAME + " VARCHAR,"
+ COLUMN_MOVIESUMMERY + " VARCHAR,"
+ COLUMN_IMAGEURL + " VARCHAR," + ");";
public MoviesOpenHelper (Context context) {
super(context, DATABASENAME, null, DATABASEVERSION);
}
//this wiil create the DB in the name "MOVIES"
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL(CREATE_TABLE_MOVIES);
Log.e("data", "Table movies created");
}
//updates the new DB
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS " + TABLE_MOVIES);
onCreate(db);
}
}
Upvotes: 0
Views: 927
Reputation: 506
CREATE TABLE IF NOT EXISTS tblmovies(movieId INTEGER PRIMARY KEY AUTOINCREMENT,movieName VARCHAR,movieSummery VARCHAR,imageURL VARCHAR,);
This is because of the trailing comma after the last VARCHAR keyword…
Upvotes: 2