我想創建一個登錄頁面,並使用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. 無法解析方法'setAdapter()'
- 2. 方法無法解析
- 3. getTabHost() - 無法解析方法
- 4. 無法解析方法setGroup
- 5. 無法解析方法setListAdapter
- 6. 無法解析方法ComputeDistanceBetween
- 7. 無法解析'SetPositiveButton'方法
- 8. 無法解析getAssets()方法
- 9. 無法解析方法onActivityResult
- 10. getSupportFragmentManager()無法解析方法
- 11. 方法無法解析
- 12. 無法解析方法setOnChildClickListener
- 13. 無法解析方法getText()
- 14. 無法解析方法maketext
- 15. 無法解析方法onKeyDown
- 16. 無法解析方法getSupportFragmentManager
- 17. 無法解析方法startactivity()
- 18. getChildFragmentManager - 無法解析方法
- 19. 無法解析方法getlatitude()
- 20. 無法解析方法'toByteArray()'
- 21. 無法解析方法`setLatestEventInfo`
- 22. 無法解析方法 'getWindow()'
- 23. 無法解析方法:CameraSource.Builder.setAutoFocusEnabled
- 24. ViewPage.addOnPageChangeListener方法無法解析
- 25. ActivityCompat.checkSelfPermission無法解析方法
- 26. 無法解析方法getLocationSettingsStates()
- 27. 無法解析方法'requestLocationUpdates
- 28. 無法解析setLatestEventInfo方法
- 29. 無法解析方法startActivity()
- 30. 無法解析方法getFilter()方法
PLS。分享你的代碼。 –