Cloud Store @ NGNLIVE

Friday, April 1, 2011

[Chinese][Android]sqlite exception: database not open

手冊跟範例都不會告訴你的事,大家的API Demo都很美妙.
但是如果你和我ㄧ樣一直碰到這個exception,但是程式又沒錯,有興趣看英文的,可以先跳轉看這篇文章. 原文在此 http://www.outofwhatbox.com/blog/2010/12/android-closing-those-database-objects/
原PO作者是建議在onDestroy的時候別忘了呼叫DbHelper的onClose (範例如下)
public void onDestroy() {
super.onDestroy();
// Replace mDbHelper as needed with your database connection, or
// whatever wraps your database connection. (See below.)
mDbHelper.close();
}
其實這個exception的原因都差不多,重點就是可以把DbHelper的open跟close放在真正做sql command的地方,基本上就不會看到IllegalStateException了.

No comments: