java������1310���������������������������������������,安卓:java.lang.IllegalStateException:数据库xxx.db(conn# 0)已关闭

百度翻译此文  有道翻译此文问题描述

I have read a lot of topics about this error message but I can't resolve my problem.

I have an app on google play and I get some error reports from the users. When I am trying the app, everything works fine.

In the application, I am managing a big database with something like 30 tables. I am closing the database in my main activity onDestroy() and all the cursors are closed when the query is finished.

I really don't know why from time to time the users are getting this error message.

Here is the entire error log:

java.lang.IllegalStateException: database /data/data/mdpi.android/databases/LocalDatabase.db (conn# 0) already closedat android.database.sqlite.SQLiteDatabase.verifyDbIsOpen(SQLiteDatabase.java:2213)at android.database.sqlite.SQLiteDatabase.queryWithFactory(SQLiteDatabase.java:1565)at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1525)at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1605)at mdpi.android.database.LocalDatabase.getHistoryLastSuccessfullUpdate(LocalDatabase.java:661)at mdpi.android.Journals$7.onItemClick(Journals.java:723)at android.widget.AdapterView.performItemClick(AdapterView.java:292)at android.widget.Gallery.onSingleTapUp(Gallery.java:960)at android.view.GestureDetector.onTouchEvent(GestureDetector.java:1310)at android.widget.Gallery.onTouchEvent(Gallery.java:937)at android.view.View.dispatchTouchEvent(View.java:5724)at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1964)at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1725)at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1970)at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1739)at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1970)at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1739)at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1970)at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1739)at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1970)at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1739)at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1970)at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1739)at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1970)at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1739)at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:2071)at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1405)at android.app.Activity.dispatchTouchEvent(Activity.java:2426)at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:2019)at android.view.View.dispatchPointerEvent(View.java:5904)at android.view.ViewRootImpl.deliverPointerEvent(ViewRootImpl.java:3155)at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2670)at android.view.ViewRootImpl.processInputEvents(ViewRootImpl.java:1000)at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2679)at android.os.Handler.dispatchMessage(Handler.java:99)at android.os.Looper.loop(Looper.java:137)at android.app.ActivityThread.main(ActivityThread.java:4517)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:993)at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:760)at dalvik.system.NativeStart.main(Native Method)

And another one:

java.lang.RuntimeException: Unable to start activity ComponentInfo{mdpi.android/mdpi.android.UserInformations}: java.lang.IllegalStateException: database /data/data/mdpi.android/databases/LocalDatabase.db (conn# 0) already closedat android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2202)at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2237)at android.app.ActivityThread.access$600(ActivityThread.java:139)at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1262)at android.os.Handler.dispatchMessage(Handler.java:99)at android.os.Looper.loop(Looper.java:154)at android.app.ActivityThread.main(ActivityThread.java:4974)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:784)at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)at dalvik.system.NativeStart.main(Native Method)Caused by: java.lang.IllegalStateException: database /data/data/mdpi.android/databases/LocalDatabase.db (conn# 0) already closedat android.database.sqlite.SQLiteDatabase.verifyDbIsOpen(SQLiteDatabase.java:2194)at android.database.sqlite.SQLiteDatabase.queryWithFactory(SQLiteDatabase.java:1536)at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1496)at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1576)at mdpi.android.database.LocalDatabase.getUserInformations(LocalDatabase.java:357)at mdpi.android.UserInformations.onCreate(UserInformations.java:122)at android.app.Activity.performCreate(Activity.java:4538)at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1071)at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2158)... 11 more

EDIT: One new error.

Today, I got a new error related to the database access:

java.lang.RuntimeException: An error occured while executing doInBackground()at android.os.AsyncTask$3.done(AsyncTask.java:278)at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)at java.util.concurrent.FutureTask.setException(FutureTask.java:124)at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)at java.util.concurrent.FutureTask.run(FutureTask.java:137)at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)at java.lang.Thread.run(Thread.java:856)Caused by: java.lang.NullPointerExceptionat android.database.sqlite.SQLiteStatement.releaseAndUnlock(SQLiteStatement.java:290)at android.database.sqlite.SQLiteStatement.executeInsert(SQLiteStatement.java:115)at android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1718)at android.database.sqlite.SQLiteDatabase.insert(SQLiteDatabase.java:1591)at mdpi.android.database.LocalDatabase.insertCountry(LocalDatabase.java:143)at mdpi.android.database.CountryTable.EnterCountry(CountryTable.java:21)at mdpi.android.UserInformations$insertCountryAsync.doInBackground(UserInformations.java:270)at mdpi.android.UserInformations$insertCountryAsync.doInBackground(UserInformations.java:1)at android.os.AsyncTask$2.call(AsyncTask.java:264)at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)... 4 more推荐答案

onDestroy() will only be called when the activity is finished/destroyed/removed from stack. When you are moving out of the activity onStop() will be called. If you need to keep your current design, just call close in onStop(). NOTE: onStop of the current activity will be called after onCreate/onRestart of the new/next activity.

If you have one single DB you can use an SQLiteOpenHelper class as mentioned by paweliebaAlso you can have the sqlite db reference in the Application class, and you can just use the reference in all activities, like

((MyApplication)getApplication()).db

Just open the DB in onCreate() of the Application class and close it in onTerminate().

You can also take a look at other SO answers for this error. It has been asked a lot of times before.

java.lang.illegalstateexception database not open android

Android java.lang.IllegalStateException database already closed

Android insert the data SQLite error Caused by java.lang.IllegalStateException: database not open

jdk 8官方下载-jdk 8最新版下载v8.0.1310.11 正式版-旋风软件园Java 存档下载 — Java SE 8 | Oracle 中国jdk1.8官方下载|jdk1.8 v8.0.1310.11 64位 官方版-520下载站Java 8 發行版本變更Oracle Java SE Support RoadmapAndroid:java.lang.illegalstateException:数据 …javax.imageio.IIOException: Can't read input file ...老师,我把所有的配置都做好了,还是连接不上mysql8-慕课网大目_慕课网精英讲师 - IMOOCThe server time zone value ‘�й���׼ʱ��‘ is unrecognized or represents more than one time ...mybatis解决 java.sql.SQLException: The server time zone value ‘�й���׼ʱ��‘ is unrecognized...java.sql.SQLException: The server time zone value ‘�й���׼ʱ��‘ is unrecognized or ...Idea 控制台总是输出 Picked up _JAVA_OPTIONS: -Djava.net.preferIPv4Stack=true��MySql报错:java.sql.SQLException: The server time zone value '�й���׼ʱ��' is unrecognized or...java.sql.SQLException: The server time zone value '�й���׼ʱ��' is unrecognized or represents...java.sql.SQLException: The server time zone value ‘�й���׼ʱ��‘ iMybatis运行项目时差错误: The server time zone value ‘�й���׼ʱ��‘ is unrecognized or......Mybatis-Plus报错:java.sql.SQLException: The server time zone value ‘�й���׼ʱ��‘ is ...mysql时区错误The server time zone value ‘�й���׼ʱ��jdbc报错:java.sql.SQLException: The server time zone value ‘�й���׼ʱ��’ is unrecognizedmybatis-generato生成代码报错The server time zone value '�й���׼ʱ��' is unrecognized or ...magick ghostscript 时执行到$im->readImage遇到PDFDelegateFailed `ϵͳ�Ҳ���ָ�����ļ��� ...java.sql.SQLException: The server time zone value '�й���׼ʱ��' is unrecognized or represent....Mybatis报错: The server time zone value ‘�й���׼ʱ��‘ is unrecognized异常报错汇总三--java.sql.SQLException: The server time zone value '�й���׼ʱ��' is ...java 连接数据库问题The server time zone value ‘�й���׼ʱ��‘ is unrecognized or represents ...链接数据库报错java.sql.SQLException: The server time zone value ‘�й���׼ʱ��java.sql.SQLException: The server time zone value ‘�й���׼ʱ��’ is unrecognized or ...初次使用mybatis时报错 java.sql.SQLException: The server time zone value ‘�й���׼ʱ��‘ is ...解决JDBC连接MySQL 8时得异常:java.sql.SQLException: The server time zone value '�й���׼ʱ��' ...
录像机监控设置方法什么什么蓝什么四字词语有哪些情侣图一人一张赖猫与狮子的倒影今天不播吗华为手机怎么投屏到win10电脑上长株潭合并获批住建部皮尔卡丹真实照片典型题是什么意思背景模板素材大骨盆和小骨盆的解剖图2020-2021跨年文案