NullReferenceException Error - InfoPath Dev
in

InfoPath Dev

NullReferenceException Error

Last post 06-10-2009 06:40 AM by Gagan. 6 replies.
Page 1 of 1 (7 items)
Sort Posts: Previous Next
  • 06-08-2009 07:05 AM

    • Gagan
    • Top 500 Contributor
    • Joined on 06-02-2009
    • Posts 31

    NullReferenceException Error

    Hi there,

     I have some code which updates a xml file with the values entered into my form, and then shot over to a custom sharepoint list. the problem is i keep getting a "NullReferenceException was unhandled by user code" error. when i debug it, it tells me "Object reference not set to an instance of an object." but the weird thing is, it only happens with my time imput, my date seems to update the list just fine. here is my code...

    the debug error occurs on the "Dim todaystime As String...." line, also i have tried changing innerxml to value, but it did not work.

     

    Dim root As XPathNavigator = MainDataSource.CreateNavigator()

    Dim todaysdate As String = root.SelectSingleNode("my:myFields/my:Date", NamespaceManager).Value

    Dim todaystime As String = root.SelectSingleNode("my:myFields/my:Time", NamespaceManager).InnerXml

    Dim batch As XPathNavigator = DataSources("AddListItem").CreateNavigator()

    batch.SelectSingleNode("/Batch/Method/Field[@Name='Date']", NamespaceManager).SetValue(todaysdate)

    batch.SelectSingleNode("/Batch/Method/Field[@Name='Time']", NamespaceManager).SetValue(todaystime)

    DataConnections("WebServiceSubmit").Execute()

     

  • 06-09-2009 10:37 PM In reply to

    Re: NullReferenceException Error

    Hi,

    Once verify root.SelectSingleNode("my:myFields/my:Time", NamespaceManager) is null or not. In your case it is null I think. Use the below code.

    If(root.SelectSingleNode("my:myFields/my:Time", NamespaceManager) != null)

    {

    Dim todaystime As String = root.SelectSingleNode("my:myFields/my:Time", NamespaceManager).InnerXml;
    }

    Swathip
    www.ggktech.com
  • 06-10-2009 06:08 AM In reply to

    • Gagan
    • Top 500 Contributor
    • Joined on 06-02-2009
    • Posts 31

    Re: NullReferenceException Error

    Hi, thank you so much for the response, i re-wrote the code a little, like this...

    If (root.SelectSingleNode("my:myFields/my:Time", NamespaceManager) != Nothing) Then

    Dim todaystime As String = root.SelectSingleNode("my:myFields/my:Time", NamespaceManager).InnerXml

    End If

     

    but it is giving me an error under the "=" in "!=" saying "Identifyer expected" any idea why?

  • 06-10-2009 06:12 AM In reply to

    Re: NullReferenceException Error

    Hi,

    Once go through the below link.

    http://www.xtremevbtalk.com/showthread.php?t=146950

    Swathip
    www.ggktech.com
  • 06-10-2009 06:26 AM In reply to

    • Gagan
    • Top 500 Contributor
    • Joined on 06-02-2009
    • Posts 31

    Re: NullReferenceException Error

    I'm not sure how that helps? That forum post you have linked is for checking if somethign is not something, in my case i am checking if it is something correct? something being "Nothing". please correct me if i am wrong, i am pretty new to visual basic, and coding in general.

     Thanks for the quick response!

  • 06-10-2009 06:36 AM In reply to

    Re: NullReferenceException Error

    Hi,

    You are using != in the code. Use <> instead of this. This what they explained in that link.

    Swathip
    www.ggktech.com
  • 06-10-2009 06:40 AM In reply to

    • Gagan
    • Top 500 Contributor
    • Joined on 06-02-2009
    • Posts 31

    Re: NullReferenceException Error

    i see. i did try using that, along with "NOT" but i get the following error.

    "Error 1 Operator '<>' is not defined for types 'System.Xml.XPath.XPathNavigator' and 'System.Xml.XPath.XPathNavigator'."

     thank you again for helping me through this

Page 1 of 1 (7 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.