_id、name、および lname の 3 つの列を格納したという点で、1 つのプレポップ SQLite データベースを作成しました。そのため、データベースからデータを取得できません。
PrepopSqliteDbActivity.java
public class PrepopSqliteDbActivity extends ListActivity {
private static final String DB_NAME = "test";
private static final String TABLE_NAME = "friends";
private static final String FRIEND_ID = "_id";
private static final String FRIEND_NAME = "name";
private static final String FRIEND_LNAME = "lname";
private SQLiteDatabase database;
private ListView listView;
private ArrayList<String> friends;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ExternalDbOpenHelper dbOpenHelper = new ExternalDbOpenHelper(this,
DB_NAME);
database = dbOpenHelper.openDataBase();
fillFreinds();
setUpList();
}
private void setUpList() {
setListAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, friends));
listView = getListView();
listView.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
Toast.makeText(getApplicationContext(),
((TextView) view).getText().toString(),
Toast.LENGTH_SHORT).show();
}
});
}
private void fillFreinds() {
friends = new ArrayList<String>();
Cursor friendCursor = database.query(TABLE_NAME, new String[] {
FRIEND_ID, FRIEND_NAME, FRIEND_LNAME }, null, null, null, null,
FRIEND_NAME, FRIEND_LNAME);
friendCursor.moveToFirst();
if (!friendCursor.isAfterLast()) {
do {
String name = friendCursor.getString(1);
String lname = friendCursor.getString(2);
friends.add(name);
friends.add(lname);
} while (friendCursor.moveToNext());
}
friendCursor.close();
}
}
エラー = illegalArgumentException: 無効な LIMIT 句: lname