onSets.close();
inメソッドでカーソルを閉じようとするとgetData()
、その位置にデータが表示されません。カーソルメソッドを閉じないと、Eclipseは文句を言い、ベースまたはカーソルが閉じられていないと言います。c.moveToFirst();
しかし、メソッドに行を追加してもgetSets(String toexes_ids, String toprog_dif)
、エラーは表示されません。何故ですか?私には2つの方法があります:
MyDatabase.javaの1つのメソッド
public Cursor getSets(String toexes_ids, String toprog_dif) {
SQLiteDatabase db = getReadableDatabase();
SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
String [] sqlSelect = {"_id", "exes_ids", "sets_ids", "sets_weight", "sets_ones"};
String sqlTables = "Sets";
String selection = "exes_ids = " + toexes_ids + " AND " + "prog_dif = " + toprog_dif;
qb.setTables(sqlTables);
Cursor c = qb.query(db, sqlSelect, selection, null, null, null, null);
c.moveToFirst();
return c;
}
MainActivity.javaの2番目のメソッド
public void getData() {
db = new MyDatabase(this);
onSets = db.getSets(toexes_ids, toprog_dif);
ListAdapter adapter = new SimpleCursorAdapter(this,
R.layout.itemsets, onSets,
new String[] {"sets_ids", "sets_weight", "sets_ones"},
new int[] {R.id.itemsets_ids, R.id.itemsets_weight, R.id.itemsets_ones});
listSets.setAdapter(adapter);
db.close();
}
エラー:
12-29 16:17:09.335: D/dalvikvm(571): GC_CONCURRENT freed 393K, 53% free 2759K/5767K, external 1574K/1802K, paused 5ms+10ms
12-29 16:17:09.355: E/Database(571): close() was never explicitly called on database '/data/data/com.exp.exp_betta/databases/fitsdbsqlite3'
12-29 16:17:09.355: E/Database(571): android.database.sqlite.DatabaseObjectNotClosedException: Application did not close the cursor or database object that was opened here
12-29 16:17:09.355: E/Database(571): at android.database.sqlite.SQLiteDatabase.<init>(SQLiteDatabase.java:1847)