I’m trying to pass my dbhelper instance from one activity to another using this code
private void onCategoriesClick() {
private DbAdapter db;
db = new DbAdapter(this);
Intent i = new Intent(this, CategoriesActivity.class);
Bundle b = i.getExtras();
b.putSerializable("db", db); //geting NullPointerException here
startActivityForResult(i, 0);
DbAdapter class implements Serializable
I’m geting confused, could anybody point my mistake?
getExtras() returns null, because you haven’t put any extras into the Intent before you call it. This means that b == null, hence the NPE. Just put the serializable in the intent directly.
In general, though, avoid passing serializables over intents if you can help it.