尝试在android studio中创建sqlite表时出现语法错误

时间:2016-07-22 19:39:50

标签: android-studio android-sqlite

我正在搜索大约2小时(谷歌,YouTube和这里)我做错了什么,但无法理解它是什么。我在日志中收到此错误

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

从我到目前为止发现的我没有使用任何sqlite保留字并且create table中的空格都可以....这是我的代码:

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 个答案:

答案 0 :(得分:1)

  

CREATE TABLE IF NOT NOT EXISTS tblmovies(movieId INTEGER PRIMARY KEY AUTOINCREMENT,movieName VARCHAR,movieSummery VARCHAR,imageURL VARCHAR,);

这是因为最后一个VARCHAR关键字之后的逗号...