android: error on SQLiteDatabase rawQuery (fetching data)

Posted by Jin on Stack Overflow See other posts from Stack Overflow or by Jin
Published on 2011-01-15T03:47:37Z Indexed on 2011/01/15 3:53 UTC
Read the original article Hit count: 154

Filed under:
|
|

So I have a SQliteDatabase mDb. It only has one column, and its data are Strings for previously saved inputs. I'm trying to populate all the data from mDb into a String[] for AutoCompleteTextView (so that the autocomplete is based on previous inputs), and here's my code to get all of the String.

public String[] fetchAllSearch() {
 ArrayList<String> allSearch = new ArrayList<String>();
 Cursor c = mDb.rawQuery("select * from " + DATABASE_TABLE, null);
 c.moveToFirst();
 if (c.getCount() > 0) {
  do {
   allSearch.add(c.getString(c.getColumnIndex("KEY")));
  } while (c.moveToNext());
 }
 String[] foo = (String[]) allSearch.toArray();
 if (foo == null) {
  foo = new String[] {""};
 }

 return foo;
}

my CREATE_TABLE command is

private static final String DATABASE_CREATE = "create table " + DATABASE_TABLE;
..

public void onCreate(SQLiteDatabase db) {

            db.execSQL(DATABASE_CREATE);
        }

But for some reason the line mDb.rawQuery(...) is giving me "no such table found" exception, and for the life of me I can't figure out why. Any pointers?

© Stack Overflow or respective owner

Related posts about android

Related posts about query