Android java. Lang. illegalstateexception: Database not open solution

Source: Internet
Author: User

05-12 18:51:14. 676: E/androidruntime (22729): Java. Lang. illegalstateexception: Database not open
05-12 18:51:14. 676: E/androidruntime (22729): at Android. database. SQLite. sqlitedatabase. insertwithonconflict (sqlitedatabase. Java: 1526)
05-12 18:51:14. 676: E/androidruntime (22729): At com. ailk. DB. netdb. addnetappflow (netdb. Java: 391)
05-12 18:51:14. 676: E/androidruntime (22729): At com. ailk. Android. sjb. mysmsservice. getapptrafficlist (mysmsservice. Java: 458)
05-12 18:51:14. 676: E/androidruntime (22729): At com. ailk. Android. sjb. mysmsservice. recordflow (mysmsservice. Java: 138)
05-12 18:51:14. 676: E/androidruntime (22729): At com. ailk. Android. sjb. mysmsservice $ 3.run( mysmsservice. Java: 122)
05-12 18:51:14. 676: E/androidruntime (22729): At java. Lang. thread. Run (thread. Java: 1019)
05-12 18:54:29. 246: E/androidruntime (27041): Fatal exception: thread-13
05-12 18:54:29. 246: E/androidruntime (27041): Java. Lang. nullpointerexception
05-12 18:54:29. 246: E/androidruntime (27041): At com. ailk. Android. sjb. mysmsservice. getapptrafficlist (mysmsservice. Java: 478)
05-12 18:54:29. 246: E/androidruntime (27041): At com. ailk. Android. sjb. mysmsservice. recordflow (mysmsservice. Java: 138)
05-12 18:54:29. 246: E/androidruntime (27041): At com. ailk. Android. sjb. mysmsservice $ 3.run( mysmsservice. Java: 122)
05-12 18:54:29. 246: E/androidruntime (27041): At java. Lang. thread. Run (thread. Java: 1019)
05-12 18:58:17. 796: E/androidruntime (28654): Fatal exception: thread-16
05-12 18:58:17. 796: E/androidruntime (28654): Java. Lang. nullpointerexception
05-12 18:58:17. 796: E/androidruntime (28654): At com. ailk. Android. sjb. mysmsservice. getapptrafficlist (mysmsservice. Java: 478)
05-12 18:58:17. 796: E/androidruntime (28654): At com. ailk. Android. sjb. mysmsservice. recordflow (mysmsservice. Java: 138)
05-12 18:58:17. 796: E/androidruntime (28654): At com. ailk. Android. sjb. mysmsservice $ 3.run( mysmsservice. Java: 122)

05-12 18:58:17. 796: E/androidruntime (28654): At java. Lang. thread. Run (thread. Java: 1019)

Method {

Sqlitedatabase DB = getreadabledatabase ();

...

DB. Close ();

}



Incorrect practice:

Method B (){

 Sqlitedatabase
DB = getreadabledatabase ();

Call method ();

DB. insert and other operations report error

}


Correct practice:

Method B (){

 

Call method ();

Sqlitedatabase DB = getreadabledatabase ();

DB. insert and other operations report error

}


Note: If the database is disabled, an error is returned!


TIPS:

Getreadabledatabase () is not used to open the database in read-only mode. Instead, getwritabledatabase () is executed first. It is called only when a failure occurs.
Both the getwritabledatabase () and getreadabledatabase () methods can obtain a sqlitedatabase instance used to operate the database.
However, the getwritabledatabase () method opens the database in read/write mode. Once the disk space of the database is full, the database can only read but cannot write,
An error occurs when getwritabledatabase () is opened to the database. The getreadabledatabase () method first opens the database in read/write mode,
If the disk space of the database is full, the database will fail to be opened. If the disk space of the database fails to be opened, the database will continue to be opened in read-only mode.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.