邓富贵儿1996 2016-05-15 11:30 采纳率: 0%
浏览 1394

android.database.Cursor错误!

 public class DLXMainActivity extends AppCompatActivity
{
    DatabaseHelper databaseHelper;
    MyAdapter adapter;
    private static Toolbar toolbar;
    public static EditText dlx_Input1,dlx_Input2;
    public static String datetime;
    public static TextView mTitle,mContent,mTime;
    ListView listView;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dlx_task3_dlxmain);
        findViews();
        setSupportActionBar(toolbar);
        databaseHelper = new DatabaseHelper(
                this, databaseHelper.DATABASE_NAME, null, databaseHelper.DATABASE_VERSION);
        List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
        Map<String, Object> map;
        databaseHelper = new DatabaseHelper(this,DatabaseHelper.DATABASE_NAME,null,1);
        for(int i=0;i<10;i++)
        {
            map = new HashMap<String, Object>();
            String title = null,content = null,time = null;
            while(databaseHelper.Querytitle().moveToNext()){

                title = databaseHelper.Querytitle().getString(databaseHelper.Querytitle().getColumnIndex("title"));
                content = databaseHelper.Querytitle().getString(databaseHelper.Querytitle().getColumnIndex("content"));
                time = databaseHelper.Querytitle().getString(databaseHelper.Querytitle().getColumnIndex("time"));
            }
            map.put("title",String.valueOf(title));
            map.put("content", String.valueOf(content));
            map.put("time",String.valueOf(time));
            list.add(map);
        }
        adapter = new MyAdapter(this,list);
        listView.setAdapter(adapter);
    }

完全新手!想把数据库里的内容放到页面上,错误Caused by: android.database.CursorIndexOutOfBoundsException: Index -1 requested, with a size of 8,求大家指点!!!!!

  • 写回答

2条回答 默认 最新

  • Robot-C 2016-05-15 11:42
    关注

    做android 开发的经常会遇android.database.CursorWindowAllocationException这样子的错误;一般出现这样的错误,大部分原因是因为没有关闭cursor,或者是因为Cursor使用不当,之前我的遇到这样的代码:
    ForecastData situation = null;
    ................
    Cursor cursor......
    答案就在这里:android开发数据库Cursor 错误android.database.CursorWindowAllocationException
    ----------------------你好,人类,我是来自CSDN星球的问答机器人小C,以上是依据我对问题的理解给出的答案,如果解决了你的问题,望采纳。

    评论

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作