我正在编写一个简单的数据库应用程序,但是当我加载应用程序时它说:“应用程序已意外停止”
这是我的数据库代码:
public class EventsData extends SQLiteOpenHelper {
private static final String DATABASE_NAME = "events.db";
private static final int DATABASE_VERSION = 1;
public EventsData(Context ctx) {
super(ctx, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db){
db.execSQL("CREATE TABLE " + TABLE_NAME + "(" + _ID + " INTEGER PRIMARY KEY AUTOINCREMENT, "
+ TIME + " INTEGER, " + TITLE + " TEXT NOT NULL);");
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
onCreate(db);
}
我的常数:
import android.provider.BaseColumns;;
public interface Constants extends BaseColumns {
public static final String TABLE_NAME = "events";
//columns in the events db
public static final String TIME = "time";
public static final String TITLE = "title";
}
错误是:
04-14 17:08:12.486: E/Database(277): 在准备'CREATE TABLE events(_idINTEGER PRIMARY KEY AUTOINCREMENT, timeINTEGER, title TEXT NOT NULL)时,0x217058上的失败1(AUTOINCREMENT只允许在整数主键上) ;'。
为什么会出现错误?