I am a newbie of android world. I have a problem of the coding. It was just a tiny error buy i dont know it doesnt work even i change others method but the error still the s
Initialize the DatabaseHelper:
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.surveyinstruction);
DatabaseHelper db = new DatabaseHelper(this);
//...
}
I had a similar problem with getId from the database. I found that I was not taking the database from mainAcitivity.java.
public adapter(Context mCtx, int listLayoutRes, List<employee> employeeList,SQLiteDatabase mDatabase) {
super(mCtx, listLayoutRes, employeeList);
this.mCtx = mCtx;
this.listLayoutRes = listLayoutRes;
this.employeeList = employeeList;
this.mDatabase = mDatabase;
}
and using this constructor from mainAcitivity
adpt= new adapter(this,R.layout.row,employeeList,mdatabase);
solved my problem. I hope this helps.
You have not initialized your reference to DatabaseHelper myDb;. Thats why the nullpointer exception.