我在 getWritableDatabase() 上遇到了 NullPointerException 问题
public class DatabaseTable extends Activity {
private Context context;
@Override
public void onCreate(Bundle savedInstanceState) {
LBD conection = LBD.get(this);
super.onCreate(savedInstanceState);
}
}
有一个实现不起作用“openHelper.getWritableDatabase()”
public class LBD {
private Context context;
private static SQLiteDatabase db;
private OpenHelper openHelper;
public static LBD get(Context context) {
LBD lbd = new LBD(context);
lbd.open();
return lbd;
}
public LBD(Context c) {
context = c;
}
final public void open() {
openHelper = new OpenHelper(context);
db = openHelper.getWritableDatabase();
}
public class OpenHelper extends SQLiteOpenHelper {
OpenHelper(Context context) {
super(context, "rss_base.db", null, 3);
}
}
}
我意识到,我忘了初始化onCreate 谢谢大家