在使用Android SQLite插入数据时,您可能会遇到如下错误:'table dict has 2 columns but 3 values were supplied'。这个错误通常是因为您的建表语句中定义的列数与插入语句提供的参数数量不匹配。

您提供的代码片段表明,您的建表语句中只定义了两个列('word'和'detail'),但您的插入语句中却提供了三个值('null'、'word'和'detail')。

public static final String CREATE_TABLE_SQL = "create table dict(_id integer primary key autoincrement, word text, detail text)";

为了解决这个问题,您需要修改建表语句,为'_id'列添加一个名称和数据类型,例如使用'integer'类型。修改后的建表语句如下:

public static final String CREATE_TABLE_SQL = "create table dict(_id integer primary key autoincrement, word text, detail text)";

这样,您的插入语句就可以正常执行了。

Android SQLite插入数据报错:'table dict has 2 columns but 3 values were supplied' 解决方法

原文地址: https://www.cveoy.top/t/topic/iyjl 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录