一个非常简单的 SQL 语句不起作用,有什么想法吗?
rawQuery("SELECT * FROM " + CITY_TABLE + ";", columns);
来自堆栈跟踪的错误
android.database.sqlite.SQLiteBindOrColumnIndexOutOfRangeException:
bind or column index out of range: handle 0x19b098006-
其余的代码
public ArrayList<String> getCitiesFromCountry(int countryCode){
String[] columns = new String[]{CITY_NAME};
ArrayList<String> cityNames = new ArrayList<String>();
Cursor cursor = sqLiteDatabase.rawQuery("SELECT * FROM " + CITY_TABLE + ";", columns);
if (cursor != null){
while(cursor.moveToNext()){
cityNames.add(cursor.getString(cursor.getColumnIndex(CITY_NAME)));
....
}
...
}
return cityNames;
}
数据库常量
public static final String WORLD_DATABASE = "world_database";
public static final String COUNTRY_TABLE = "country_table";
public static final String CITY_TABLE = "city_table";
public static final int DATABASE_VERSION = 1;
public static final String _ID = "_id";
public static final String _ID2 = "_id2";
public static final String COUNTRY_NAME = "country_name";
public static final String CITY_NAME = "city_name";