0

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);

}

}

1 Answer 1

2

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…

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

8 Comments

thanks but i delted it but still gives me this error: 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,);
@rollcage You did not delete it : VARCHAR,imageURL VARCHAR**,**);
hmm ok i see that even if i change the CREATE TABLE IF NOT EXISTS to just CREATE TABLE. it will still show up the same error in the log.... ill to restart androud studio...
@rollcage Please turn on your brain… There is comma just before the closing bracket in your CREATE statement. It cannot work with a comma here.
yes im trying yo use it and i told you i deleted the comma from: + COLUMN_IMAGEURL + " VARCHAR," + ");"; so now it look like this: + COLUMN_IMAGEURL + " VARCHAR" + ");"; but still gave me the same error... it like its not updating that or somthing...
|

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.