} public static void main(String args[]){ new hey(); }} when I compile it, I will get NullPointException even if I will check s.length()<0; or s.length()>0; why is that? Jaffery
Steven Wong
Ranch Hand
Joined: Mar 07, 2002
Posts: 295
posted
0
Hi, That's because your string variable was not explicitly initialized by you, thus it will be implicitly initialized to null. Clement
Due to short circuit nature of && operator, the condition s.length()==0 will be evaluated only when s is not null. HTH, - Manish
Thomas Paul
mister krabs
Ranch Hand
Joined: May 05, 2000
Posts: 13974
posted
0
Originally posted by Jaffery Rab: when I compile it, I will get NullPointException even if I will check s.length()<0; or s.length()>0; why is that? Jaffery
In fact, the s.length() will cause a NullPointerException because you are running a method on a null!
Jaffery- Just a suggestion -- but try giving your posts a descriptive subject instead of "help" give it something like "NullPointerException with String.length()" -- Just an idea
Corey McGlone
Ranch Hand
Joined: Dec 20, 2001
Posts: 3271
posted
0
Originally posted by Jessica Sant: Jaffery- Just a suggestion -- but try giving your posts a descriptive subject instead of "help" give it something like "NullPointerException with String.length()" -- Just an idea
To go along with what Jessica said - giving your posts a good topic makes them easier to search for. If someone wanted to find something on a NullPointerException, they might never find your thread. Corey