我收到了通常有效的代码的崩溃报告。
例外是在Insertorthrow中启动的,是:" exception android.database.sqlite.sqliteconstraintexception:不是零约束失败:history.Altitude(代码1299(。
所有字段在表中都声明为无效,尤其是历史记录。
我无法理解它是如何零的,因为我在插入命令上填充了几行。
任何人都知道如何可能吗?
synchronized public void addSample( long time, int method, float altitude, int accuracy )
{
...
ContentValues cv = new ContentValues();
long day = new TimeUtils.Day(time).getMillis();
cv.put(MetaData.COLUMN_DAY, day);
cv.put(MetaData.COLUMN_TIME, time);
cv.put(MetaData.COLUMN_ALTITUDE, altitude);
cv.put(MetaData.COLUMN_METHOD, method);
cv.put(MetaData.COLUMN_ACCURACY, accuracy);
long id = latestSample.mId;
id = mDb.insertOrThrow(MetaData.TABLE_NAME, null, cv); // <--- Here crash
...
}
在这里,用于定义表的代码:
/* Inner class that defines the table contents */
public static abstract class MetaData implements BaseColumns
{
public static final String TABLE_NAME = "HISTORY";
public static final String COLUMN_DAY = "day";
public static final String COLUMN_TIME = "time";
public static final String COLUMN_ALTITUDE = "altitude";
public static final String COLUMN_METHOD = "method";
public static final String COLUMN_ACCURACY = "accuracy";
}
private static final String SQL_CREATE_HISTORY_TABLE =
"CREATE TABLE " + MetaData.TABLE_NAME + " ( " +
MetaData._ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
MetaData.COLUMN_DAY + " INTEGER NOT NULL, " +
MetaData.COLUMN_TIME + " INTEGER NOT NULL, " +
MetaData.COLUMN_ALTITUDE + " REAL NOT NULL, " +
MetaData.COLUMN_METHOD + " INTEGER NOT NULL, " +
MetaData.COLUMN_ACCURACY + " INTEGER NOT NULL " +
" );n" +
"CREATE INDEX " + MetaData.COLUMN_METHOD + " ON " + MetaData.TABLE_NAME + " (" + MetaData.COLUMN_METHOD + ");n" +
"CREATE INDEX " + MetaData.COLUMN_DAY + " ON " + MetaData.TABLE_NAME + " (" + MetaData.COLUMN_DAY + ");n" +
"CREATE INDEX " + MetaData.COLUMN_TIME + " ON " + MetaData.TABLE_NAME + " (" + MetaData.COLUMN_TIME + ");";
sqlite不允许将其视为NAN,并将其视为null。因此,如果您的float
值最终以某种方式成为NAN,它将违反无效的约束。