Brownman Revival Brownman Revival - 8 months ago 44
Java Question

Check returned value by res is null

this is my code to check if the value of column is not null


but I get this:

java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String java.lang.String.trim()' on a null object reference

What is the proper way to check if value return by res is empty


Try this,

if(res != null){
    if(res.getString(res.getColumnIndex("answerquestionid")) != null && !res.getString(res.getColumnIndex("answerquestionid")).trim(‌​).equals("")) 

//your stuff