locked
checking object != null throws exception RRS feed

  • Question

  • Hi I have an object that is PersonData,  {first name , last name , telephone number}

    When I check the condition  if (Person==null), this works fine. It could be null when there is no data associated with telephone number.

    but i check the condition if(PersonData !=null) then I get exception. 

    Not sure why I am seeing the exception 


    i am a novice and a student

    Thursday, July 18, 2013 5:59 AM

Answers

  • I'm intreseting in telephone is null make your personData is null too. do you rewrite equal function? if does ,check the function.

    • Marked as answer by Jason Dot Wang Wednesday, July 31, 2013 10:07 AM
    Thursday, July 18, 2013 9:06 AM

All replies

  • Hi,

    I don't understand you test two différents objets "Person" and "PersonData", it's a mistake on your message ?

    Can you specify the exception which is thrown ?

    Best Regards,


    Yan Grenier

    Thursday, July 18, 2013 6:34 AM
  • Sorry it is PersonData

    i am a novice and a student

    Thursday, July 18, 2013 6:47 AM
  • OK, but which exception is thrown ?

    Best regards,


    Yan Grenier

    Thursday, July 18, 2013 6:51 AM
  • Object is not set to an instance

    i am a novice and a student

    Thursday, July 18, 2013 7:25 AM
  • As a novice one of the key things that you will need to learn is the emphasis on detail in programming.  It is all about detail and accuracy.

    Your question is far too vague for anyone to answer.  You need to show your exact code, not a general description using imprecise words but the actual code.  Use the 'Insert Code Block' tool in the forum editor.  When you receive an exception you need to record (use copy/paste) the exact exception.  The name of an exception is important, the message is important, the stack trace is important, the precise line which generates the exception is important,  any input provided is important.

    Your original post amounted to 'I did something, then I changed it and something went wrong'


    Paul Linton

    Thursday, July 18, 2013 7:45 AM
  • Where is "PersonData" ? It's a field or a property with a getter ?

    I think your code is more complex than you write, and without all informations it's difficult to analyze your problem.

    But I think your "PersonData" is not a field but a property of an null object and perhaps a test is missing before access the real PersonData.

    Best regards


    Yan Grenier

    Thursday, July 18, 2013 7:56 AM
  • I'm intreseting in telephone is null make your personData is null too. do you rewrite equal function? if does ,check the function.

    • Marked as answer by Jason Dot Wang Wednesday, July 31, 2013 10:07 AM
    Thursday, July 18, 2013 9:06 AM