android sqlite异常:java.lang.IllegalArgumentException:列’_id’不存在

我用以下列创建了一个sql lite数据库:

static final String dbName="demoDB";
    static final String tableName="Employees";
    static final String colID="EmployeeID";

然后

public void onCreate(SQLiteDatabase db) {
        // TODO Auto-generated method stub
        db.execSQL("CREATE TABLE "+tableName+" ("+colID+" INTEGER PRIMARY KEY AUTOINCREMENT, "+
                colName+" TEXT, "+colAge+" Integer);");
    }

我想像这样选择数据库中的所有记录并在gridview中显示它们:

SQLiteDatabase db=this.getWritableDatabase();
         Cursor cur= db.rawQuery("Select "+colName+", "+colAge+" from "+tableName, new String [] {});

String [] from=new String []{DatabaseHelper.colName,DatabaseHelper.colAge};
            int [] to=new int [] {R.id.colName,R.id.colAge};
            SimpleCursorAdapter sca=new SimpleCursorAdapter(this,R.layout.gridrow,c,from,to);


        GridView grid=(GridView)findViewById(R.id.grid);
        grid.setAdapter(sca);

但我收到以下例外:

java.lang.IllegalArgumentException: column '_id' does not exist.

db表没有名为’_id’的列

所以这段代码出了什么问题

谢谢

解决方法:

解决此问题的方法是使用这样的选择语句

选择EmpId作为_id

因为适配器需要一个名为_id的列,如你所说

谢谢

相关文章

SQLite架构简单,又有Json计算能力,有时会承担Json文件/RES...
使用Python操作内置数据库SQLite以及MySQL数据库。
破解微信数据库密码,用python导出微信聊天记录
(Unity)SQLite 是一个软件库,实现了自给自足的、无服务器...
安卓开发,利用SQLite实现登陆注册功能