Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialStephen Ford
2,836 PointsHello Treehouse family, "if" statement using null.
Hello Treehouse family,
In this video Ben uses an "if" statement and then places "null" as the response returned if there is no textField entry.
I did not find this method to work. I tested it by placing a toast within the "if" statement and went to work. I found if I set the "if" statement to if(name != null) I would finally get into the body of the if statement.
After looking around I found the method ".matches("") " in this case... if(name.matches("")){} and this worked. I have found this in Java programming in the past as well. A textField not used still has a value therefore null is not applicable.
Just wondering what the guru's had to add... :)
Cheers
1 Answer
miguelcastro2
Courses Plus Student 6,573 PointsTextView in Android returns a CharSequence , which can either be empty or not. So like you discovered it does not return null and perhaps did in prior versions of Android.