重大な問題が発生しました。私のアプリケーションは Google Play にあります。今日、Google Play の開発者コンソールにアクセスすると、2 つのエラー ログが表示されます。どちらも同じ内容です。
スタックトレースは次のとおりです。
java.lang.IllegalStateException: attempt to re-open an already-closed object: SQLiteDatabase: /data/data/pl.snowvision/databases/snow_pilot
at android.database.sqlite.SQLiteClosable.acquireReference(SQLiteClosable.java:55)
at android.database.sqlite.SQLiteDatabase.queryWithFactory(SQLiteDatabase.java:1156)
at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1032)
at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1200)
at pl.snowvision.helpers.Entity.getEntities(Entity.java:139)
at pl.snowvision.fragments.stations.StationsList.showListByName(StationsList.java:163)
at pl.snowvision.fragments.stations.StationsList.onCreateView(StationsList.java:140)
at android.support.v4.app.Fragment.performCreateView(Fragment.java:1460)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:911)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1088)
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1444)
at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:429)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4898)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
at dalvik.system.NativeStart.main(Native Method)
以下に、問題を引き起こす StationsList.java:163 で呼び出されるメソッドを含めます。
public static ArrayList<Entity> getEntities(String entityId, String catId, String parentId, Context context, String... orderKeys) {
ArrayList<Entity> entities = new ArrayList<Entity>();
DbHelper database = DbHelper.getInstance(context);
SQLiteDatabase db = database.getReadableDatabase();
String whereClause = "";
if(entityId != null)
whereClause = EntityTable.KEY_ID + " = " + "\"" + entityId + "\"";
if(catId != null) {
if(entityId != null)
whereClause += " AND ";
whereClause += EntityTable.KEY_CATEGORYID + " = " + "\"" + catId + "\"";
}
if(parentId != null) {
if(catId != null || (catId == null && entityId != null))
whereClause += " AND ";
whereClause += EntityTable.KEY_PARENTID + " = " + "\"" + parentId + "\"";
}
Cursor eCursor = db.query(EntityTable.TABLE_NAME, null, whereClause, null, null, null, null);
if(eCursor != null && eCursor.getCount() > 0) {
while(eCursor.moveToNext()) {
String id = eCursor.getString(eCursor.getColumnIndex(EntityTable.KEY_ID));
String categoryId = eCursor.getString(eCursor.getColumnIndex(EntityTable.KEY_CATEGORYID));
String pId = eCursor.getString(eCursor.getColumnIndex(EntityTable.KEY_PARENTID));
Entity tmpEntity;
if(orderKeys != null && orderKeys.length > 0)
tmpEntity = new Entity(id, categoryId, pId, new String[]{orderKeys[0]});
else
tmpEntity = new Entity(id, categoryId, pId);
Cursor iCursor = db.query(ItemsTable.TABLE_NAME, null, ItemsTable.KEY_PARENTID + "=\"" + id + "\"", null, null, null, null);
if(iCursor != null) {
while(iCursor.moveToNext()) {
String key = iCursor.getString(iCursor.getColumnIndex(ItemsTable.KEY_KEY));
String value = iCursor.getString(iCursor.getColumnIndex(ItemsTable.KEY_VALUE));
tmpEntity.addPair(key, value);
}
}
iCursor.close();
entities.add(tmpEntity);
}
}
eCursor.close();
return entities;
}
この問題の正確な原因と修正方法について何か考えはありますか? 助けてくれてありがとう!