0

拜托,我真的是 SQLite 的新手。

我不明白为什么我会出现这个错误。

我想这是罪魁祸首,当 SQLiteOpenHelper 尝试创建表时

public class PendingiIntentsDatabaseHandler extends SQLiteOpenHelper {

private static final int DATABASE_VERSION = 1;

// Database Name
private static final String DATABASE_NAME = "pendingintents";

// Contacts table name
private static final String TABLE_REFERENCES = "references";

// Contacts Table Columns names
private static final String KEY_CLASS = "class";
private static final String KEY_REQUESTCODE = "requestCode";


public PendingiIntentsDatabaseHandler(Context context) {
    super(context, DATABASE_NAME, null, DATABASE_VERSION);
}

// Creating Tables
@Override
public void onCreate(SQLiteDatabase db) {
    String CREATE_EVENTS_TABLE = "CREATE TABLE " + TABLE_REFERENCES + "("
            + "_id" + " INTEGER PRIMARY KEY AUTOINCREMENT,"
            + KEY_CLASS +  " TEXT," 
            + KEY_REQUESTCODE + " TEXT"
            +
            ")";
    db.execSQL(CREATE_EVENTS_TABLE);
}

这是 LogCat:

09-28 18:25:27.703: E/AndroidRuntime(2213): FATAL EXCEPTION: IntentService[ScheduledService]
09-28 18:25:27.703: E/AndroidRuntime(2213): android.database.sqlite.SQLiteException: near "references": syntax error: CREATE TABLE references(_id INTEGER PRIMARY KEY AUTOINCREMENT,class TEXT,requestCode TEXT)
09-28 18:25:27.703: E/AndroidRuntime(2213):     at android.database.sqlite.SQLiteDatabase.native_execSQL(Native Method)
09-28 18:25:27.703: E/AndroidRuntime(2213):     at android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1763)
09-28 18:25:27.703: E/AndroidRuntime(2213):     at com.examples.android.calendar.scheduler.PendingiIntentsDatabaseHandler.onCreate(PendingiIntentsDatabaseHandler.java:44)
09-28 18:25:27.703: E/AndroidRuntime(2213):     at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:126)
09-28 18:25:27.703: E/AndroidRuntime(2213):     at com.examples.android.calendar.scheduler.PendingiIntentsDatabaseHandler.addPendingIntentReference(PendingiIntentsDatabaseHandler.java:63)
09-28 18:25:27.703: E/AndroidRuntime(2213):     at com.examples.android.calendar.scheduler.Scheduler.schedule(Scheduler.java:50)
09-28 18:25:27.703: E/AndroidRuntime(2213):     at com.examples.android.calendar.crisismate2.OnBootService.onHandleIntent(OnBootService.java:43)
09-28 18:25:27.703: E/AndroidRuntime(2213):     at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:59)
09-28 18:25:27.703: E/AndroidRuntime(2213):     at android.os.Handler.dispatchMessage(Handler.java:99)
09-28 18:25:27.703: E/AndroidRuntime(2213):     at android.os.Looper.loop(Looper.java:130)
09-28 18:25:27.703: E/AndroidRuntime(2213):     at android.os.HandlerThread.run(HandlerThread.java:60)
4

1 回答 1

4

'References' 是 SQL 中的保留名称

于 2013-09-28T16:44:23.973 回答