This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes String.equals() throws null exception Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "String.equals() throws null exception" Watch "String.equals() throws null exception" New topic
Author

String.equals() throws null exception

Patrick Muls
Greenhorn

Joined: Aug 08, 2001
Posts: 25
Hello,
I try to compare 2 strings, but when they are different, I get a nullpointer exception:
Here is the method:

frameNo and plateNo were filled in previously, as you can see in the following output:

So here it worked just fine when they're all true, but when there is a difference:

[ June 04, 2002: Message edited by: Dirk Schreckmann ]
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
A NullPointerException is "thrown when an application attempts to use null in a case where an object is required" not when comparing two strings that are different.
In your example, plaat must not have been properly initialized, as it is null.
[ June 04, 2002: Message edited by: Dirk Schreckmann ]

[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
Patrick Muls writes:
Dirk,
Thank you for replying to my posting. As it turned out, after I installed JCreator Pro and debugged the problem, neither plaat nor plateNo were null, as shown in the output, but in the method vervangRecord() another variable was still null. But because I didn�t see the 2 println that came before this method, I didn�t look that far.
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
That's great that you figured this one out. I've posted your email here so that others might learn a thing or two from your experience.
Hope to see you 'round the Ranch!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: String.equals() throws null exception