如何解决这个问题? :尝试重新查询一个已经关闭的游标android.database.sqlite.SQLiteCursor@409dfcd0 [英] How fix this error? : trying to requery an already closed cursor android.database.sqlite.SQLiteCursor@409dfcd0

查看:352
本文介绍了如何解决这个问题? :尝试重新查询一个已经关闭的游标android.database.sqlite.SQLiteCursor@409dfcd0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我M搜索在计算器和google.But我不觉得out.I写这篇code.it这个错误是工作在集成电路4.0.3,但它提供了在Android 3.2的错误。我做我的主要的Java不understand.This code file.when我转到另一个页面,回头就给出了error.Why的错误?我该如何解决?

SQLiteDatabase DB = databaseHelper.getReadableDatabase();              光标光标= db.query(DatabaseHelper.TABLE_NAME,新的String [] {_ ID,ISIM,icerik},NULL,NULL,NULL,NULL,NULL);              startManagingCursor(光标);              TTS = 0;

 而(cursor.moveToNext()){
            如果(TTS == 0)
             {
            array_spinner =新的String [cursor.getCount()+ 1];
            array_spinner [TTS] =FAVORİ;
             }
            array_spinner2 [TTS + 1] = cursor.getString((cursor.getColumnIndex(ISIM)));
            array_spinner3 [TTS + 1] = cursor.getString((cursor.getColumnIndex(icerik)));
             TTS ++;
            }

         SS2 =(微调)findViewById(R.id.spinner2);
         ArrayAdapter<对象>适配器=新的ArrayAdapter<对象>(这一点,R.layout.row2,R.id.weekofday2,array_spinner2);
            ss2.setAdapter(适配器);
        }赶上(例外五){}
 

解决方案

某处,你是关闭光标要传递到 startManagingCursor() 。呼叫 stopManagingCursor()结束前的光标

注意 startManagingCursor()是pcated德$ P $。而不是使用,当你的数据的变化,在后台运行另一个查询(例如,的AsyncTask CursorLoader )。

此外,您可以考虑使用的CursorAdapter ,像 SimpleCursorAdapter ,而不是手动将所有的数据到对象,并使用 ArrayAdapter

另外,如果你要使用 ArrayAdapter ,请用更具体的类中声明它(例如, ArrayAdapter<字符串> ,不是 ArrayAdapter<对象>

I m search this error in stackoverflow and google.But I dont find out.I writing this code.it is working on ics 4.0.3 but it gives that error on android 3.2. I do not understand.This code on my main java file.when I goto another page and turn back it gives that error.Why that error? How can I fix?

SQLiteDatabase db = databaseHelper.getReadableDatabase(); Cursor cursor = db.query(DatabaseHelper.TABLE_NAME, new String[]{"_id","isim","icerik"}, null, null, null, null, null); startManagingCursor(cursor); tts=0;

         while(cursor.moveToNext()){
            if(tts==0)
             {            
            array_spinner=new String[cursor.getCount()+1];
            array_spinner[tts]= "FAVORİ";
             }
            array_spinner2[tts+1]= cursor.getString((cursor.getColumnIndex("isim")));
            array_spinner3[tts+1]= cursor.getString((cursor.getColumnIndex("icerik")));
             tts++;
            } 

         ss2 = (Spinner) findViewById(R.id.spinner2);
         ArrayAdapter<Object> adapter  = new ArrayAdapter<Object>(this,R.layout.row2, R.id.weekofday2, array_spinner2);
            ss2.setAdapter(adapter);
        } catch (Exception e) {}

解决方案

Somewhere, you are closing the Cursor you are passing to startManagingCursor(). Call stopManagingCursor() before closing the Cursor.

Note that startManagingCursor() is deprecated. Instead of using that, when your data changes, run another query in the background (e.g., AsyncTask, CursorLoader).

Also, you might consider using a CursorAdapter, like SimpleCursorAdapter, rather than manually converting all of the data into objects and using an ArrayAdapter.

Also, if you are going to use ArrayAdapter, please declare it with a more concrete class (e.g., ArrayAdapter<String>, not ArrayAdapter<Object>.

这篇关于如何解决这个问题? :尝试重新查询一个已经关闭的游标android.database.sqlite.SQLiteCursor@409dfcd0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆