Android SQLiteException: table has incorrect column count during insertion
The error 'android.database.sqlite.SQLiteException: table 'dict' has 2 columns but 3 values were supplied (code 1 SQLITE_ERROR): , while compiling: insert into dict values(null,?,?)' arises when your SQLite database insertion statement provides a different number of values than the table has columns. The error message explicitly tells you that the table 'dict' has two columns but your INSERT statement attempts to insert three values.
To resolve this, you need to ensure your INSERT statement's values match the number of columns in your table.
Example:
Let's assume your 'dict' table has two columns: 'column1' and 'column2'. The correct INSERT statement would be:
String query = "INSERT INTO dict (column1, column2) VALUES (?, ?)";
You then need to provide values for each column:
String value1 = 'value1';
String value2 = 'value2';
db.execSQL(query, new Object[]{value1, value2});
Key Takeaway: Always verify that the number of values provided in your INSERT statement aligns with the number of columns in your SQLite table to avoid this common error.
原文地址: https://www.cveoy.top/t/topic/i34w 著作权归作者所有。请勿转载和采集!