出错原因:在查询整个sqlite数据库时,没有查询到 "_id" 这一列。

原来的代码是:mSQLiteDatabase.query(table_name, new String[] {_title}, null, null, null, null, null);

修改后的代码为:mSQLiteDatabase.query(table_name, null, null, null, null, null, null);

        这里的 new String[] {MyEvent._title} 是一个查询条件,数组里的内容是要查询表的列名,这里是限定你要查询的列。参数值为 null 表示查询所有列(包含有 “_id” 这一列) 。如里这样改也是可以 的:mSQLiteDatabase.query(table_name, new String[] {_id, _title}, null, null, null, null, null); 目的就是要你查询的结果中含有“_id” 这一列。

        另外,关于sqlite数据库中的 "_id" 这一列,在sqlite数据库中是必须有的,而且列名还必须是 “_id” 一般为主键。而用以下代码在一个ListView中显示时,也需要用到 “_id” 这一列。

public void updataAdapter() {
        if (mCursor != null && !mCursor.isClosed())
            mCursor.close();
        
        mCursor = m_MyDataBaseAdapter.fetchAllData();
        mCursor.moveToFirst();
        
        if (mCursor != null && mCursor.getCount() > 0) {
            ListAdapter adapter = new SimpleCursorAdapter(this, android.R.layout.simple_list_item_1, mCursor, new String[] { _title }, new int[] { android.R.id.text1 });
            listView.setAdapter(adapter);
        }
 }

        这里的 SimpleCursorAdapter 在显示时会根据"_id"进行显示,“_id” 是必须有的。

       


更多相关文章

  1. Android(安卓)EditText的设置
  2. Android中Messenger原理及基本用法详解
  3. android ImageView 频繁切换图片 OOM
  4. android 加载时闪烁点样式的启动画面
  5. AcitonBar自定义布局
  6. Android——高德地图地点搜索框
  7. 记录下android studio 重命名包名
  8. NDK入门
  9. Android开发之屏幕元素层次结构

随机推荐

  1. Android(安卓)自定义弹出对话框实例
  2. 音乐播放器之简单播放(MediaPlayer、Servi
  3. android在String资源文件中加入符号
  4. 魅族MX2 Smartbar的支持
  5. Android(安卓)学习笔记--android――Asyn
  6. 【Android(安卓)Developers Training】 2
  7. 使用android中的AIDL让Service与Activity
  8. 【Android】创建Popwindow弹出菜单
  9. cocos2d-x在android真机上设置帧率无效的
  10. android修改图片(修改图片大小,图片旋转,图