CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 2011

    system.nullreference exception...

    can any body pls help me...while i run the below code...i get the error,"object reference not set to an instance of the object"....what may be the problem...can any one help me...
    namespace ClassLibrary15
    public class Class1

    #region Temporary Recording Code
    public static void RecordedTest1()

    UIAEditBox uiaeditbox0 = Desktop.UIA[@" Business Suite", @"TfrmMain", @"UIAWindow"][@"Login", @"TfrmEverestLogin", @"UIAWindow"][@"UIAPane", 1][@"UIAEditBox", 1] as UIAEditBox;

    uiaeditbox0.Click(MouseButtons.Left, new Point(78, 12));
    UIAButton login2 = Desktop.UIA[@" Business Suite", @"TfrmMain", @"UIAWindow"][@"Login", @"TfrmEverestLogin", @"UIAWindow"][@"UIAPane", 0][@"Login", @"TBitBtn", @"UIAButton"] as UIAButton;
    // login2 = new login2();
    login2.Click(MouseButtons.Left, new Point(42, 18));
    UIAPane uiapane3 = Desktop.UIA[@" Business Suite - Back Office - Sample Demo and Training Company", @"TfrmMain", @"UIAWindow"][@"UIAPane", 0][@"UIAPane", 0] as UIAPane;
    // uiapane3 = new uiapane3();
    uiapane3.Click(MouseButtons.Left, new Point(27, 30));
    UIAButton close4 = Desktop.UIA[@" Business Suite - Back Office - Sample Demo and Training Company", @"TfrmMain", @"UIAWindow"][@" Business Suite - Back Office - Sample Demo and Training Company", @"", @"TitleBar"][@"Close", @"", @"Close"] as UIAButton;
    // close4 = new close4();
    close4.Click(MouseButtons.Left, new Point(12, 4));
    UIAButton yes5 = Desktop.UIA[@"Confirm", @"TMessageForm", @"UIAWindow"][@"Yes", @"TButton", @"UIAButton"] as UIAButton;
    // yes5 = new yes5();
    yes5.Click(MouseButtons.Left, new Point(65, 6));


  2. #2
    Join Date
    May 2011
    Washington State

    Re: system.nullreference exception...

    I really do hate giving these sort of 'non answers', but to try and be of help, I just need a little more info...

    The message simply states one of the objects you are referencing (trying to use) in this method has not been created. Which line does the exception occure on? Beyond that, I would say that once you find out which line (which object: yes5, close4, uiapane3...etc) the exception is talking about, look further into the Desktop.UIA[] process from which your program is trying to gain a reference to find out why you are not getting one as you expect... without knowing what Desktop.UIA[] does, I don't have a good guess for you as to what it might be.

    Perhaps somone else here who has seen what you're doing before can offer more of a solution for you, best of luck!

  3. #3
    Join Date
    Jun 2008

    Re: system.nullreference exception...

    1. You're using the safe cast (as) operator, yet you don't check for a null return value. That defeats the whole purpose of using the safe cast and makes matters worse than they would be if you had simply used a normal, C-style cast.
    2. You have some messy lookups into what appears to be a hash or 3 dimensional array. It is overly optimistic and you are assuming that those values will always exist. You perform absolutely no error checking.
    3. You do not need the @ symbol to create a verbatim string in *any* of those strings. At all. Get rid of them as they serve only to obfuscate further what is already messy code.
    4. You create buttons, don't add them to any control, and then call what must be a custom Click method. What is that supposed to do? I don't understand what you are even trying to accomplish with this code.
    5. Learn to use the debugger. You can easily catch a null reference exception. They are among the easiest bugs to isolate.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.