Brownman Revival Brownman Revival - 25 days ago 9
Java Question

Check returned value by res is null

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

if(!res.getString(res.getColumnIndex("answerquestionid")).trim().equals("")){


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

Answer

Try this,

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

//your stuff

}