I am trying to create a login page and connect go to SQLite database using SQLiteOpenHelper class. But the default code in SQLiteOpenHelper.java shows error at line db.reopenReadWrite(); I checked that SQLiteDatabase.java file has the method reopenReadWrite(); Can u help me fix this
Asked
Active
Viewed 535 times
1
-
1Pls. share your code. – Pritesh Patel Oct 11 '17 at 18:35
1 Answers
2
This method is hidden with the @hide javadoc attribute as you can see in the source code:
/**
* Reopens the database in read-write mode.
* If the database is already read-write, does nothing.
*
* @throws SQLiteException if the database could not be reopened as requested, in which
* case it remains open in read only mode.
* @throws IllegalStateException if the database is not open.
*
* @see #isReadOnly()
* @hide
*/
public void reopenReadWrite() {
synchronized (mLock) {
throwIfNotOpenLocked();
if (!isReadOnlyLocked()) {
return; // nothing to do
}
// Reopen the database in read-write mode.
final int oldOpenFlags = mConfigurationLocked.openFlags;
mConfigurationLocked.openFlags = (mConfigurationLocked.openFlags & ~OPEN_READ_MASK)
| OPEN_READWRITE;
try {
mConnectionPoolLocked.reconfigure(mConfigurationLocked);
} catch (RuntimeException ex) {
mConfigurationLocked.openFlags = oldOpenFlags;
throw ex;
}
}
}
Since it is not part of the public API, you can't use that method without using Reflection.
The best route would be to just use the methods that are in the public API, listed in the SQLiteDatabase documentation.
All you should need is the SQLiteOpenHelper#getReadableDatabase()
method, which in turn calls getDatabaseLocked()
, which internally calls db.reopenReadWrite()
:
public SQLiteDatabase getReadableDatabase() {
synchronized (this) {
return getDatabaseLocked(false);
}
}
private SQLiteDatabase getDatabaseLocked(boolean writable) {
if (mDatabase != null) {
if (!mDatabase.isOpen()) {
// Darn! The user closed the database by calling mDatabase.close().
mDatabase = null;
} else if (!writable || !mDatabase.isReadOnly()) {
// The database is already open for business.
return mDatabase;
}
}
if (mIsInitializing) {
throw new IllegalStateException("getDatabase called recursively");
}
SQLiteDatabase db = mDatabase;
try {
mIsInitializing = true;
if (db != null) {
if (writable && db.isReadOnly()) {
db.reopenReadWrite();
}
//.......................

Daniel Nugent
- 43,104
- 15
- 109
- 137