I have a DB in my app which normally works perfectly.
Now, I have added a widget with an update function which also accesses the DB.
Once in a while, I get this error but only from within the widget update method.
Caused by:java.lang.NullPointerException
at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:118)
Is there some kind of restriction on accessing a DB from within widget update method?
You shouldn't do any disk IO from the widget's BroadCast receiver ( onUpdate()
). Start a service that fetches the data and does the actual update. You might want to use an IntentServcie
since it starts a worker thread by default.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.