【问题标题】:Android SQLite: rawQuery troubleshootAndroid SQLite:rawQuery 疑难解答
【发布时间】:2011-12-24 05:41:15
【问题描述】:

好的,所以我一直在这个论坛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;
            }

想不出任何其他可能有帮助的信息,如果需要更多信息,请直接说出来,我会发布的。提前致谢

【问题讨论】:

    标签: android sqlite android-2.2-froyo


    【解决方案1】:

    我看到的三个证据:

    1) 您的模拟器正在锁定。
    2) 根据我的经验,while 语句因导致锁定而臭名昭著。
    3) 你不知道你的 while 语句是做什么的,但你需要它。

    测试建议:

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

    【讨论】:

    • 感谢您的帮助,这极大地帮助了整个应用程序的故障排除
    猜你喜欢
    • 2013-06-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-06
    • 2014-08-29
    • 2011-10-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多