I am parsing values from an xml file. For certain fields the parser returns null values. I am having problems in handling these values.
Following is the piece of code:
The xml returns null values for birthDate in some cases. So in such cases the if loop shouldn't execute which is not the case. I tried printing birthDate to the console and it does return null. I don't understand the problem. Kindly help!
I am new to this forum btw so apologies if I violated any conventions.
Could you please UseCodeTags next time? They will preserve formatting and add syntax highlighting.
Are you sure the value of birthDate is null, and not "null"? The latter is a String that will be printed the same as null. Perhaps you could modify the printout:
If this will show "birthDate == null; value is null: false" then birthDate will be "null" instead of null.
I think it's unlikely that birthDate is null - if it was, the .trim() method would be throwing a NullPointerException on line 3. So Rob's suggestion is certainly possible. What does the XML look like at that point?
Joined: May 31, 2011
Yeah I checked it again and its "null" and not null. My bad. The code is working now. Thanks very much.
And I'll post using Ranch Conventions from now on.