public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.tab2);   
  db = new DBAdapter(this, sql_myfavorite, myfavorite); // this.getApplicationContext()
  db.open();
  String columns[] = { "name", "code" };
  Cursor cursor = db.selectTable(columns, null, null, null, null, null);
  ArrayList<HashMap<String, String>> list = new ArrayList<HashMap<String, String>>();
 cursor.moveToFirst();
  while (cursor.moveToNext()) {
   HashMap<String, String> map = new HashMap<String, String>();
   map.put("name", cursor.getString(0));
   map.put("code", cursor.getString(1));
   list.add(map);
  }
  SimpleAdapter sap = new SimpleAdapter(this, list,
    android.R.layout.simple_list_item_1, new String[] { "name", "code" }, 
    new int[] { android.R.id.text1, android.R.id.text2 });
  lv = (ListView) findViewById(R.id.tab2_lView);
  lv.setAdapter(sap);
  cursor.close();
  db.close();   
 }


05-23 14:36:34.297: ERROR/Database(3784): android.database.sqlite.DatabaseObjectNotClosedException: Application did not close the cursor or database object that was opened here

 

위와같은 오류가 납니다. db.close(); 도 해주고 cursor.close(); 도 해줬는데 왜이러는지 모르겠네요 ㅠ

 

 public DBAdapter open() throws SQLException {
  // 외부에서 db를 사용하겠다고 요청이 들어오면 Helper를 이용해서 db를 open하고
  // 자신의 클래스를 리턴
  mHelper = new DatabaseHelper(mCxt);  // SQLiteOpenHelper에게 context를 넘겨준다.
  mDb = mHelper.getWritableDatabase();
  return this;
 }

 

오류나는곳은 mDb = mHelper.getWritableDatabase(); 이 부분에서 오류가 납니다.

테이블도 생성이 되질 않네요...