Android SQLite:rawQuery故障排除

时间:2011-12-24 05:41:16

标签: android sqlite android-2.2-froyo

好吧所以我一直在研究这个“动态加载一个微调器”来自这个论坛anddev.org我修复了我已经得到的强制关闭错误我现在遇到的问题当我开始使用我的sql时变量,从模拟器开始它对我来说是锁定的,好像光标卡在一个循环中,logcat没有显示任何错误。关于它可能会粘在一起或搞乱的任何想法?

public static final String KEY_ROWID = "_rowid";
    public static final String KEY_ONE = "serial";
    public static final String KEY_TWO = "name";
    public static final String KEY_THREE = "place";

    private static final String KEY_DB = "DbTester";
    private static final String KEY_TABLE = "DbTable";
    private static final int VERSION = 1;

    //static final String DB_NAME="contacts";
    //static final String NAMES_TABLE="names";
    private DbHelper ourHelper;
    private final Context ourContext;
    private SQLiteDatabase ourDB;
    SQLiteDatabase db=null;

然后这是我的方法loadSpinner()

DbHelper dbhelper=new DbHelper(this.ourContext, KEY_TABLE, null, 2);
            db=dbhelper.getWritableDatabase();

            Cursor c=db.rawQuery("SELECT * FROM "+KEY_TWO, null);

            if(c != null) {

            while(!c.isLast())
                    c.moveToNext(); //I dont understand why but it's necessary (alternative call c.getCount() )

            String[] from=new String[1];
            from[0]="name";

            int[] to=new int[1];
            to[0]=android.R.id.text1;


            SimpleCursorAdapter adapter=new SimpleCursorAdapter(this.ourContext, android.R.layout.simple_spinner_item, c, from, to);


           c.close();
            db.close();

            return adapter;
            }

无法想到任何其他可能有帮助的事情,如果需要更多信息,我会发布它。提前致谢

1 个答案:

答案 0 :(得分:2)

我看到三件证据:

1)您的模拟器已锁定。
2)根据我的经验,虽然声明因引起锁定而臭名昭着 3)你不知道你的while语句是做什么的,但你需要它。

测试建议:

尝试用if语句替换while,并只调用一次c.MoveToNext()并查看是否仍然获得锁定。如果是这样,你就缩小了问题范围。