Checking the zero line in android

I am developing an Android application. I get String as null from webservice. I retrieve the value and store it in a String variable. Then, when I print the value using Log, for example Log.i ("tag", "` `!!! cell β†’" + cell) ;, I get a zero printed on the screen. Now I need that I need to check the variable for "null", and I want to display the text field without a value if it is "null". I use the following statement to check

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

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

Please give me a solution.

Thanks in advance.

+6
source share
8 answers

when cell is null and you try to call a method on it, you will be thrown into a null pointer exception.

I would say

 if(cell !=null && !cell.isEmpty()) { _______yes, disply } else { _______nope, some thing wrong } 
+10
source

its not equals(null) its

 if(cell != null || !cell.isEmpty()) 
+2
source

I would try this, it seems to work for me!

 if(TextUtils.isEmpty(yourString) && yourString == null){ } else if(!TextUtils.isEmpty(yourString) && yourString != null){ } 
+1
source

If the string value is null !cell.equals("") will evaluate to true and, therefore, it will be in the if part, and not in the else, because you are using the OR condition.

NULL! = "" (Empty string) !!!

0
source

Use this:

 if (cell != null && cell.trim().length() > 0) { // do whatever you want } else { // the string received is null } 
0
source

Android provides a simple utility

 TextUtils.isEmpty(<<stringVariable>>); 

Read more @ http://developer.android.com/reference/android/text/TextUtils.html

0
source

JOB!!!

  if (string.matches("")&& string.trim().equals("null")){ return false; } else{ return true; } 
0
source

Source: https://habr.com/ru/post/955256/


All Articles