Android的广场精简版封闭异常 [英] Android Sq Lite closed exception
本文介绍了Android的广场精简版封闭异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有同步没有坚实的回地面。我想,这个问题将是固定的,当我使用同步method.but,任何一个可以帮助我解决这个问题。 code是如下:
公开的HashMap<字符串,FriendInfo> getAllRecordsInList_HashMap(){
MySQLiteHelper dbHelper = MySQLiteHelper.getInstance(mActivity);
HashMap的<字符串,FriendInfo> list_map =新的HashMap<字符串,FriendInfo>();
SQLiteDatabase DB = dbHelper.getReadableDatabase();
//光标光标= db.rawQuery(SELECT *从+
// dbHelper.tbl_friendlist,新的String [] {});
的String [] COLS = {dbHelper.id,dbHelper.name,dbHelper.picture,dbHelper.birthday,dbHelper.livein,dbHelper.gender,dbHelper.is_online,dbHelper.is_vip};
光标光标= db.query(dbHelper.tbl_friendlist,COLS,NULL,NULL,NULL,NULL,dbHelper.name);
如果(光标=空&安培;!&安培; cursor.getCount()大于0){
//一些code这里....
}
cursor.close();
返回list_map;
}
不同势线程可以调用此方法 getAllRecordsInList_HashMap()
。请指教,如何解决这个问题,如果我做同步的方法,将它固定?先谢谢了。
java.lang.IllegalStateException:不能执行此操作,因为
连接池已关闭。
在
android.database.sqlite.SQLiteConnectionPool.throwIfClosedLocked(SQLiteConnectionPool.java:962)
在
android.database.sqlite.SQLiteConnectionPool.waitForConnection(SQLiteConnectionPool.java:599)
在
android.database.sqlite.SQLiteConnectionPool.acquireConnection(SQLiteConnectionPool.java:348)
在
android.database.sqlite.SQLiteSession.acquireConnection(SQLiteSession.java:894)
在
android.database.sqlite.SQLiteSession.executeForCursorWindow(SQLiteSession.java:834)
在android.database.sqlite.SQLiteQuery.fillWindow(SQLiteQuery.java:62)
在android.database.sqlite.SQLiteCursor.fillWindow(SQLiteCursor.java:143)
在android.database.sqlite.SQLiteCursor.getCount(SQLiteCursor.java:133)
在
com.platinumapps.friendlist.BLL_Friendlist.getAllRecordsInList_HashMap(BLL_Friendlist.java:290)
在
com.platinumapps.activities.Messages_Activity.addViewTOLayout(Messages_Activity.java:753)
在
com.platinumapps.activities.Messages_Activity.access $ 3(Messages_Activity.java:744)
在
com.platinumapps.activities.Messages_Activity $ 1 $ 3.run(Messages_Activity.java:141)
在android.app.Activity.runOnUiThread(Activity.java:4644)
在
com.platinumapps.activities.Messages_Activity $ 1.onReceive(Messages_Activity.java:136)
在android.app.LoadedApk $ ReceiverDispatcher $ Args.run(LoadedApk.java:758)
在android.os.Handler.handleCallback(Handler.java:725)
在android.os.Handler.dispatchMessage(Handler.java:92)
在android.os.Looper.loop(Looper.java:137)
在android.app.ActivityThread.main(ActivityThread.java:5039)
在java.lang.reflect.Method.invokeNative(本机方法)
在java.lang.reflect.Method.invoke(Method.java:511)
在
com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:793)
在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
在dalvik.system.NativeStart.main(本机方法)
解决方案
您不应该关闭数据库,因为它会再次在接下来的调用中使用。因此,试图删除
db.close();
从code。
I have no solid back ground of synchronization. I think, this issue will be fixed , when i use synchronized method.but, any one can help me to fix this issue. Code is below:
public HashMap<String, FriendInfo> getAllRecordsInList_HashMap() {
MySQLiteHelper dbHelper = MySQLiteHelper.getInstance(mActivity);
HashMap<String, FriendInfo> list_map = new HashMap<String, FriendInfo>();
SQLiteDatabase db = dbHelper.getReadableDatabase();
// Cursor cursor = db.rawQuery("SELECT * from " +
// dbHelper.tbl_friendlist, new String[] {});
String[] cols = { dbHelper.id, dbHelper.name, dbHelper.picture, dbHelper.birthday, dbHelper.livein, dbHelper.gender, dbHelper.is_online, dbHelper.is_vip };
Cursor cursor = db.query(dbHelper.tbl_friendlist, cols, null, null, null, null, dbHelper.name);
if (cursor != null && cursor.getCount() > 0) {
// some code here....
}
cursor.close();
return list_map;
}
Diffrent threads can call this method getAllRecordsInList_HashMap()
.Please advise ,how to fix this issue if i make synchronized method,will it be fixed?. Thanks in advance.
java.lang.IllegalStateException: Cannot perform this operation because the
connection pool has been closed.
at
android.database.sqlite.SQLiteConnectionPool.throwIfClosedLocked(SQLiteConnectionPool.java:962)
at
android.database.sqlite.SQLiteConnectionPool.waitForConnection(SQLiteConnectionPool.java:599)
at
android.database.sqlite.SQLiteConnectionPool.acquireConnection(SQLiteConnectionPool.java:348)
at
android.database.sqlite.SQLiteSession.acquireConnection(SQLiteSession.java:894)
at
android.database.sqlite.SQLiteSession.executeForCursorWindow(SQLiteSession.java:834)
at android.database.sqlite.SQLiteQuery.fillWindow(SQLiteQuery.java:62)
at android.database.sqlite.SQLiteCursor.fillWindow(SQLiteCursor.java:143)
at android.database.sqlite.SQLiteCursor.getCount(SQLiteCursor.java:133)
at
com.platinumapps.friendlist.BLL_Friendlist.getAllRecordsInList_HashMap(BLL_Friendlist.java:290)
at
com.platinumapps.activities.Messages_Activity.addViewTOLayout(Messages_Activity.java:753)
at
com.platinumapps.activities.Messages_Activity.access$3(Messages_Activity.java:744)
at
com.platinumapps.activities.Messages_Activity$1$3.run(Messages_Activity.java:141)
at android.app.Activity.runOnUiThread(Activity.java:4644)
at
com.platinumapps.activities.Messages_Activity$1.onReceive(Messages_Activity.java:136)
at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:758)
at android.os.Handler.handleCallback(Handler.java:725)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5039)
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:793)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
at dalvik.system.NativeStart.main(Native Method)
解决方案
You should not close the DB since it will be used again in the next call. So try to remove the
db.close();
from your code.
这篇关于Android的广场精简版封闭异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文