I use my cursor to get a certain value out of my database table. It gets it out of a column with the type ‘TEXT’. The idea is that the standard value of the column is blank, but when a certain button is clicked, a query will add “true” to it.
String var = c.getString(1); //use cursor to get value
But when I want to use this to compare to a string, f.e.
if(var.equals("true")) {
//do something crazy
}
I get an error on items where there is nothing filled in the DB. Only the fields where actually “true” is filled in won’t give an error. I tried c.getString(1).toString(); but this doesn’t do the trick… any ideas?
check should be like below
So that you will not get
NullPointerExceptionAs suggested in Cursor#getString Javadoc
You should use Cursor#isNull or Cursor#moveToFirst before checking value from database.