Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

String.equals() throws null exception

 
Patrick Muls
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
What are you doing? You are supposed to be reading this tiny ad!
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!