[o] SQLite数据库报错: Invalid column C

时间:2023-03-08 18:19:34

向SQLite数据库内新增列,之前出现过报错为提示no such column,通过删除并重建数据库文件解决,这次报错为无效的数据列:

java.lang.IllegalArgumentException: Invalid column C

问题原因:

ContentProvider 在关联数据库时须定义UriMatcher并将新增列写入对应Hashmap,否则无法识别到数据表的列值。

解决办法:

在ContentProvider的子类里定义 UriMatcher及Hashmap,并写入列名

public class A extends ContentProvider {

public static final String C ="c";

private static UriMatcher uriMatcher;
private NoteDatabaseOpenHelper mDbhelper;
private static HashMap<String, String> sProjectionMap; static{
uriMatcher = new UriMatcher(UriMatcher.NO_MATCH);
uriMatcher.addURI(Entity.AUTHORITY, Entity.TABLE_NOTE, NOTE_DIR);
uriMatcher.addURI(Entity.AUTHORITY, Entity.TABLE_NOTE + "/#", NOTE_ITEM);
sProjectionMap = new HashMap<String, String>();
sProjectionMap.put(Entity.C, Entity.C); //此处写入 }