Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Checking null String in android

I am developing an android application.I am getting a String value as null from webservice. I am fetching the value and storing it in a String variable. Then when I print the value using Log, like Log.i("tag", "````!!!cell >>"+cell);, I an getting null printed in the screen. Now what i need is that I need to check the variable for 'null' and I want to display a textfield with no value if it is 'null'. I am using the following statement for checking

if(!cell.equals(null) || !cell.equals("")) {
  _______
} else {
  _______
}

But the control is not going inside the else part if the value us 'null'

Please give me a solution.

Thanks in advance.

like image 763
Sundeep Avatar asked Oct 04 '13 15:10

Sundeep


3 Answers

when cell is null , and you are trying to invoke a method on it, you will hit by a null pointer exception.

I'd say

if(cell !=null  &&  !cell.isEmpty()) {
  _______yes, disply
} else {
  _______nope, some thing wrong
}
like image 134
Suresh Atta Avatar answered Nov 17 '22 14:11

Suresh Atta


its not equals(null) its

if(cell != null || !cell.isEmpty())
like image 2
tyczj Avatar answered Nov 17 '22 15:11

tyczj


Try TextUtils.html#isEmpty(java.lang.CharSequence)

like image 1
f2prateek Avatar answered Nov 17 '22 15:11

f2prateek