如何在Android contentprovider查询中选择要接受的SQLite列?

时间:2012-10-17 06:37:49

标签: android sqlite

我一直都在这上面。如果我将列选择设置为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); 

我也尝试将新String放入查询而不是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);
}

0 个答案:

没有答案