我正在编写一个ContentProvider
使用 anSqlOpenHelper
来获取其数据库的。我刚刚对数据库进行了一些重大更改,因此我将数据库的版本提高了一个。
这发生过:
02-13 15:36:15.668: E/AndroidRuntime(15917): FATAL EXCEPTION: AsyncTask #3
02-13 15:36:15.668: E/AndroidRuntime(15917): java.lang.RuntimeException: An error occured while executing doInBackground()
02-13 15:36:15.668: E/AndroidRuntime(15917): at android.os.AsyncTask$3.done(AsyncTask.java:278)
02-13 15:36:15.668: E/AndroidRuntime(15917): at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
02-13 15:36:15.668: E/AndroidRuntime(15917): at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
02-13 15:36:15.668: E/AndroidRuntime(15917): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
02-13 15:36:15.668: E/AndroidRuntime(15917): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
02-13 15:36:15.668: E/AndroidRuntime(15917): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
02-13 15:36:15.668: E/AndroidRuntime(15917): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
02-13 15:36:15.668: E/AndroidRuntime(15917): at java.lang.Thread.run(Thread.java:864)
02-13 15:36:15.668: E/AndroidRuntime(15917): Caused by: android.database.sqlite.SQLiteException: Can't upgrade read-only database from version 2 to 3: /data/data/com.company.anothercompany.anotherothercompany/databases/twocompanies
02-13 15:36:15.668: E/AndroidRuntime(15917): at android.database.sqlite.SQLiteOpenHelper.getReadableDatabase(SQLiteOpenHelper.java:262)
02-13 15:36:15.668: E/AndroidRuntime(15917): at com.somo.vertu.provider.FerrariVertuContentProvider.query(FerrariVertuContentProvider.java:94)
02-13 15:36:15.668: E/AndroidRuntime(15917): at android.content.ContentProvider$Transport.query(ContentProvider.java:189)
02-13 15:36:15.668: E/AndroidRuntime(15917): at android.content.ContentResolver.query(ContentResolver.java:315)
02-13 15:36:15.668: E/AndroidRuntime(15917): at android.content.CursorLoader.loadInBackground(CursorLoader.java:56)
02-13 15:36:15.668: E/AndroidRuntime(15917): at android.content.CursorLoader.loadInBackground(CursorLoader.java:42)
02-13 15:36:15.668: E/AndroidRuntime(15917): at android.content.AsyncTaskLoader.onLoadInBackground(AsyncTaskLoader.java:255)
02-13 15:36:15.668: E/AndroidRuntime(15917): at android.content.AsyncTaskLoader$LoadTask.doInBackground(AsyncTaskLoader.java:66)
02-13 15:36:15.668: E/AndroidRuntime(15917): at android.content.AsyncTaskLoader$LoadTask.doInBackground(AsyncTaskLoader.java:55)
02-13 15:36:15.668: E/AndroidRuntime(15917): at android.os.AsyncTask$2.call(AsyncTask.java:264)
02-13 15:36:15.668: E/AndroidRuntime(15917): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
02-13 15:36:15.668: E/AndroidRuntime(15917): ... 4 more
我getReadableDatabase()
从query(...)
函数调用是因为我在阅读,而不是在写作。在这种情况下onUpgrade()
,意味着什么都不会返回,但我正在处理。如何在不调用getWritableDatabase(...)
方法的情况下触发可写数据库的升级ContentProvider#onCreate()
?或者这是最好的做法?