Android getWritableDatabase() throws a NullPointerException

时光总嘲笑我的痴心妄想 提交于 2019-12-04 18:20:45
com.productivity.uptimeapp.NetService.<init>(NetService.java:45)

This line in the logcat suggests there's a problem instantiating your class (<init>).

In the code, there's the following member variable initialization:

DbHelper dbHelper = new DbHelper(this.getBaseContext()); 
SQLiteDatabase db = dbHelper.getWritableDatabase();

The problem is there. You cannot use the class instance as Context until onCreate(). Defer your dbHelper and db initialization to onCreate() or later.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!