Hardik Parmar
Hardik Parmar

Reputation: 712

How to check null value in the parse table using android?

I have not any idea about this. For how to check the null value from the parse table from his column. In this column to define "(undefined)".

I try like this.

if (pList.getString("zip") == "nil") {
    Log.e("in Plist if condition", ":::" + pList.getString("zip").length());
} else {
    Log.e("in Plist if else condition", ":::" + pList.getString("zip"));
}
if(pList.getString("zip") == "(undifine)"){ 
}

This type of try but I not getting the answer.

Upvotes: 1

Views: 549

Answers (3)

user5120285
user5120285

Reputation:

I am not clear on what kind of datastructure your pList is, but my general answer would be: You might want to compare objects with null, this will give check whether the string object(myString) exist or not, for example if (myString==null) than blabla... But if you want to compare if the value of a myString equals to "null" you can use for example if (myString.equals("null")) than blabla...

Upvotes: 1

N J
N J

Reputation: 27535

You can check for null like

if (!TextUtils.isEmpty("zip")) {
 }

It will Returns true if the string is null or 0-length.

See this link for TextUtils.isEmpty()

Upvotes: 1

Norbert
Norbert

Reputation: 6084

null is null not nil in java (you had it correct in the title):

if (pList.getString("zip") == null) {}

should work as a null check.

Alternative you could use try catch:

try {
   Log.e("in Plist if condition", "::: "
    + pList.getString("zip").length());
catch(NullPointerException exp) { 
   Log.e("in Plist if condition", exp);
}

Upvotes: 1

Related Questions