我想創建一個登錄頁面,並使用SQLiteOpenHelper類連接到SQLite數據庫。但SQLiteOpenHelper.java中的默認代碼在db.reopenReadWrite()行顯示錯誤。 我檢查了SQLiteDatabase.java文件的方法reopenReadWrite(); u能幫助我解決這個無法解析方法'reopenReadWrite()'
0
A
回答
1
這種方法隱藏與@hide javadoc attribute你可以在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;
}
}
}
因爲它不是公共API的一部分,你不能使用該方法,無需使用反射。
最好的方法是使用公共API listed in the SQLiteDatabase documentation中的方法。
所有,如果您需要的是SQLiteOpenHelper#getReadableDatabase()
方法,進而調用getDatabaseLocked()
,其內部調用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();
}
//.......................
+0
謝謝你幫助我! –
相關問題
- 1. 無法解析getAssets()方法
- 2. 無法解析方法setOnChildClickListener
- 3. 無法解析方法startActivity()
- 4. 無法解析方法 'getWindow()'
- 5. 無法解析方法ComputeDistanceBetween
- 6. 無法解析方法setGroup
- 7. getTabHost() - 無法解析方法
- 8. 無法解析方法`setLatestEventInfo`
- 9. 無法解析方法'requestLocationUpdates
- 10. 無法解析方法'setAdapter()'
- 11. 無法解析方法startactivity()
- 12. 無法解析方法getLocationSettingsStates()
- 13. 無法解析方法:CameraSource.Builder.setAutoFocusEnabled
- 14. ViewPage.addOnPageChangeListener方法無法解析
- 15. getSupportFragmentManager()無法解析方法
- 16. 無法解析方法setListAdapter
- 17. setText - 無法解析方法
- 18. ActivityCompat.checkSelfPermission無法解析方法
- 19. 無法解析方法getFilter()方法
- 20. 無法解析方法setAvailableProviders和無法解析符號IdpConfig
- 21. 無法解析getstring方法(java.lang.string)
- 22. 無法解析android中的keySet()方法
- 23. 無法解析方法getListView和setListAdapter(Android)
- 24. 無法解析方法setText(java.lang.String)
- 25. 無法解析靜態方法?
- 26. 無法解析方法put(java.lang.string,java.lang.string)
- 27. 無法解析方法TimeUnit行
- 28. 無法解析方法setVisibility(int)
- 29. android無法解析方法'startsWith(java.lang.string)'
- 30. Firebase.Database.Query無法解析方法'on(?,?)'
PLS。分享你的代碼。 –