简体   繁体   中英

Android SQLite: rawQuery troubleshoot

Alright so i have been working on this "Dynamic load of a spinner" from this forum anddev.org i fixed the force closing error i have been getting now the issue i have been having when i start to use my sql variables, starting on the emulator it to me is locking up and seems like the cursor is stuck in a loop, logcat doesn't show any errors. any ideas on where it might be sticking and or messed up?

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;

then here is my method 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;
            }

can't think of anything else that might help out, if anymore info is need just say so and i'll post it. Thanks in advance

Three pieces of evidence I see:

1) Your emulator is locking up.
2) In my experience, while statements are notorious for causing lockups.
3) You don't know what your while statement does, but you need it.

Testing recommendation:

Try replacing the while with if statement and make only one call to c.MoveToNext() and see if you still get the lockup. If so, you've narrowed the issue.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM