0

我一直在兜兜转转。如果我将列选择设置为 null 一切正常。当我尝试选择列时,出现致命错误“投影中的未知列”。我已经验证了列名是正确的。

这是列选择代码:

String[] MyColumns = new String[] { MyTable.COLUMN_ID, MyTable.COLUMN_A, 
    MyTable.COLUMN_B, MyTable.COLUMN_C };
Uri Myuri = MyContentProvider.CONTENT_URI; //specify the content provider location (Uri)
Cursor Mycursor = getContentResolver().query(Myuri, MyColumns, null, null, null); 

我还尝试将新字符串放入查询中,而不是 MyColumns 变量。那也失败了。帮助!有什么建议么?

@Yul,@Praful Bhatnagar:这是所要求的表创建代码(注意:这是 contentprovider 数据库):

public class MyTable {
// Define Database table and column names
public static final String TABLE_NAME = "MyTable";
public static final String COLUMN_ID = "_id";
public static final String COLUMN_A = "test1";
public static final String COLUMN_B = "test2";
public static final String COLUMN_C = "test3";

// 创建数据库的sql语句

private static final String DATABASE_CREATE = "create table " +TABLE_NAME+ "(" + 
    COLUMN_ID + " integer primary key autoincrement, " +
    COLUMN_A + " text not null," +
    COLUMN_B + " long not null," +
    COLUMN_C + " real);";

public static void onCreate(SQLiteDatabase database) {
    database.execSQL(DATABASE_CREATE);
}
4

0 回答 0