Brownman Revival Brownman Revival - 1 year ago 72
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

Answer Source

Try this,

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

//your stuff

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download