据说我有重复的列名,但我不知道。看看这段代码
这是我的架构类:
public class CrimeDBSchema {
public static final class CrimeTable{
public static final String NAME = "crimes";
public static final class Cols{
public static final String UUID = "uuid";
public static final String TITLE = "title";
public static final String DATE = "date";
public static final String SOLVED = "solved";
}
}
}
这是扩展SQLiteOpenHelper的类:
public class CrimeBaseHelper extends SQLiteOpenHelper {
private static final int VERSION = 1;
private static final String DATABASE_NAME = "crimeBase.db";
public CrimeBaseHelper(Context context){
super(context, DATABASE_NAME, null, VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("create table "+ CrimeTable.NAME + "(" +
"_id integer primary key autoincrement, " +
CrimeTable.Cols.UUID + ", " +
CrimeTable.Cols.TITLE + ", "+
CrimeTable.Cols.DATE + ", " +
CrimeTable.Cols.SOLVED + ")");
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
}
}
并且AndroidStudio认为这是我的sql语句:
create table crimes(_id integer primary key autoincrement, uuid, uuid, uuid, uuid)
当显然所有四个列名都不同且不是" uuid"。有什么想法吗?
答案 0 :(得分:0)
您将主键定义为整数数据类型,但将其他内容定义为。
public static final class Cols{
public static final String ID = "_id";
public static final String UUID = "uuid";
public static final String TITLE = "title";
public static final String DATE = "date";
public static final String SOLVED = "solved";
}
你的db.execSQL应该是这样的(定义列数据类型)
db.execSQL("create table "+ CrimeTable.NAME + "(" +
CrimeTable.Cols.ID + " integer primary key autoincrement, " +
CrimeTable.Cols.UUID + " text, " +
CrimeTable.Cols.TITLE + " text, "+
CrimeTable.Cols.DATE + " text, " +
CrimeTable.Cols.SOLVED + " text)");