IllegalStateException: attempt to re-open an already-closed object 错误

来源:互联网 发布:什么是淘宝运营 编辑:程序博客网 时间:2024/05/29 16:09



  这是错误之前的代码   

list = new ArrayList<HashMap<String, Object>>();int zongyusuan = 0;Cursor c = db.query("plans", null, null, null, null, null, null);System.out.println("------c--------" + c.getCount());for (int i = 0; i < leibie.length; i++) {if (c.moveToFirst()) {c.move(i);map = new HashMap<String, Object>();map.put("titlesub", leibie[i]);int yusuan = c.getInt(c.getColumnIndex("yusuan"));type = c.getInt(c.getColumnIndex("type"));System.out.println("在读取数据库时的预算----" + yusuan);if (yusuan != 0) {zongyusuan = yusuan + zongyusuan;map.put("yusuan", "预算: " + yusuan);map.put("yue", yusuan);}list.add(map);}title.setText("总预算" + zongyusuan);c.close();}adapter = new SimpleAdapter(Addzhidingjiahua.this, list,R.layout.addzhidingsub, new String[] { "titlesub","yusuan", "yue" }, new int[] { R.id.titlesub,R.id.yusuan, R.id.yue });listview.setAdapter(adapter);

这是修改之后的代码


list = new ArrayList<HashMap<String, Object>>();int zongyusuan = 0;Cursor c = db.query("plans", null, null, null, null, null, null);System.out.println("------c--------" + c.getCount());for (int i = 0; i < leibie.length; i++) {if (c.moveToFirst()) {c.move(i);map = new HashMap<String, Object>();map.put("titlesub", leibie[i]);int yusuan = c.getInt(c.getColumnIndex("yusuan"));type = c.getInt(c.getColumnIndex("type"));System.out.println("在读取数据库时的预算----" + yusuan);if (yusuan != 0) {zongyusuan = yusuan + zongyusuan;map.put("yusuan", "预算: " + yusuan);map.put("yue", yusuan);}list.add(map);}title.setText("总预算" + zongyusuan);}c.close();adapter = new SimpleAdapter(Addzhidingjiahua.this, list,R.layout.addzhidingsub, new String[] { "titlesub","yusuan", "yue" }, new int[] { R.id.titlesub,R.id.yusuan, R.id.yue });listview.setAdapter(adapter);
其实就是c.close()这个方法放的位置不对


0 0
原创粉丝点击