none
Object reference not set to an instance of an object.

    Question

  • When  can debugg the code it will give the error "Object reference not set to an instance of an object.".

    The code is--

     

     

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using SMC.AlphaAccounting.EntryControls;
    using SMC.AlphaAccounting.PlugIns;
    using SMC.PlugInContracts;
    using SMC.BusinessObjects;
    using SMC.Utils;
    using SMC;
    using SMC.AlphaAccounting;
    using SMC.AlphaAccounting.DataEntry;
    using Infragistics.Win.UltraWinEditors;
    using Infragistics.Win.UltraWinMaskedEdit;
    using Infragistics.Win.UltraWinToolbars;

    namespace WindowsApplication3
    {
        public partial class FormCountry : SmcDataEntry
        {
            private boGlChart boLocalGlChart;
            private boVendors boLocalVendors;
            public FormCountry()
            {
                InitializeComponent();




                this.ultraNumericUniqueID.KeyDown += new KeyEventHandler(ultraNumericUniqueID_KeyDown);
                this.ultraNumericUniqueID.KeyPress += new KeyPressEventHandler(ultraNumericUniqueID_KeyPress);
                this.ultraMaskedISOCode.KeyPress +=new KeyPressEventHandler(ultraMaskedISOCode_KeyPress);
                this.ultraMaskedISOCode.KeyDown +=new KeyEventHandler(ultraMaskedISOCode_KeyDown);
                this.ultraMaskedAlphaCode.KeyPress +=new KeyPressEventHandler(ultraMaskedAlphaCode_KeyPress);
                this.ultraMaskedAlphaCode.KeyDown +=new KeyEventHandler(ultraMaskedAlphaCode_KeyDown);
                this.ultraNumericNumCode.KeyPress +=new KeyPressEventHandler(ultraNumericNumCode_KeyPress);
                this.ultraNumericNumCode.KeyDown +=new KeyEventHandler(ultraNumericNumCode_KeyDown);
                this.ultraMaskedName.KeyPress +=new KeyPressEventHandler(ultraMaskedName_KeyPress);
                this.ultraMaskedName.KeyDown +=new KeyEventHandler(ultraMaskedName_KeyDown);
                this.ultraMaskedContinent.KeyDown += new KeyEventHandler(ultraMaskedContinent_KeyDown);
                this.ultraMaskedContinent.KeyPress += new KeyPressEventHandler(ultraMaskedContinent_KeyPress);
            }

            void ultraMaskedContinent_KeyPress(object sender, KeyPressEventArgs e)
            {
                //throw new Exception("The method or operation is not implemented.");
            }

            void ultraMaskedContinent_KeyDown(object sender, KeyEventArgs e)
            {
                //throw new Exception("The method or operation is not implemented.");
            }

           

            void ultraMaskedName_KeyDown(object sender, KeyEventArgs e)
            {
                //throw new Exception("The method or operation is not implemented.");
            }

            void ultraMaskedName_KeyPress(object sender, KeyPressEventArgs e)
            {
                //throw new Exception("The method or operation is not implemented.");
            }

            void ultraNumericNumCode_KeyDown(object sender, KeyEventArgs e)
            {
                //throw new Exception("The method or operation is not implemented.");
            }

            void ultraNumericNumCode_KeyPress(object sender, KeyPressEventArgs e)
            {
                //throw new Exception("The method or operation is not implemented.");
            }

            void ultraMaskedAlphaCode_KeyDown(object sender, KeyEventArgs e)
            {
                //throw new Exception("The method or operation is not implemented.");
            }

            void ultraMaskedAlphaCode_KeyPress(object sender, KeyPressEventArgs e)
            {
                //throw new Exception("The method or operation is not implemented.");
            }

            void ultraMaskedISOCode_KeyDown(object sender, KeyEventArgs e)
            {
                //throw new Exception("The method or operation is not implemented.");
            }

            void ultraMaskedISOCode_KeyPress(object sender, KeyPressEventArgs e)
            {
                //throw new Exception("The method or operation is not implemented.");
            }

            void ultraNumericUniqueID_KeyPress(object sender, KeyPressEventArgs e)
            {
                //throw new Exception("The method or operation is not implemented.");
            }

            void ultraNumericUniqueID_KeyDown(object sender, KeyEventArgs e)
            {
                //throw new Exception("The method or operation is not implemented.");
            }


          

            private void FormCountry_Load(object sender, EventArgs e)
            {
                //Title = GeneralRoutines.SmcFileTitle(SmcFileNumber.COUNTRY);
                //StatusBar.Panels["Name"].Text = "Country";
                //DisplayVersionNumber("COUNTRY.DLL");
                DataBindEntryControls();


                if (BusinessObject != null)
                {
                    boLocalGlChart = new boGlChart(BusinessObject.AlphaDatabaseManager, BusinessObject.LogFile, BusinessObject.VirtualDatabase);
                    boLocalGlChart.InitISmcBusinessObject(BusinessObject.AlphaDatabaseManager, BusinessObject.LogFile, BusinessObject.VirtualDatabase);
                    boLocalVendors = new boVendors(BusinessObject.AlphaDatabaseManager, BusinessObject.LogFile, BusinessObject.VirtualDatabase);
                    boLocalVendors.InitISmcBusinessObject(BusinessObject.AlphaDatabaseManager, BusinessObject.LogFile, BusinessObject.VirtualDatabase);
                }
                 
            }
            private void DataBindEntryControls()           
            {
                string sTable = _localDataSet.Tables[0].TableName;
                _bindingManagerBase = this.BindingContext[_localDataSet, sTable];
                ultraNumericUniqueID.DataBindings.Add("Text", _localDataSet, sTable + ".UNIQUEID");
                ultraMaskedISOCode.DataBindings.Add("Text", _localDataSet, sTable + ".ISO_CODE");
                ultraMaskedAlphaCode.DataBindings.Add("Text", _localDataSet, sTable + ".ALPHA_CODE");
                ultraNumericNumCode.DataBindings.Add("Text", _localDataSet, sTable + ".NUMERIC_CODE");
                ultraMaskedName.DataBindings.Add("Text", _localDataSet, sTable + ".NAME");
                ultraMaskedContinent.DataBindings.Add("Text", _localDataSet, sTable + ".CONTINENT");

            }

            private void UniqueID_TextChanged(object sender, EventArgs e)
            {

            }

            private void toolbarManager_ToolClick(object sender, ToolClickEventArgs e)
            {
                   SmcDataEntry DataEntry = new SmcDataEntry();              
                    InsertRecord();



               
            }

            private void ultraMaskedISOCode_MaskChanged(object sender, MaskChangedEventArgs e)
            {

            }

            private void ultraGroupBox1_Click(object sender, EventArgs e)
            {

            }

            private void ultraNumericUniqueID_ValueChanged(object sender, EventArgs e)
            {

            }

            private void ultraMaskedContinent_ItemNotInList(object sender,
                Infragistics.Win.UltraWinEditors.ValidationErrorEventArgs evArgs)
            {
                if (!(String.IsNullOrEmpty(ultraMaskedContinent.Text)))
                    ultraComboEditorContinent_BadInput();
            }

            private void ultraComboEditorContinent_BadInput()
            {
                MessageBox.Show("Please select a status from the drop-down list.");
                ultraMaskedContinent.Focus();
            }
           
          
        }
    }

     

    Thanx in advance.....

    • Moved by KeFang Chen Thursday, September 09, 2010 9:06 AM (From:SharePoint - Development and Programming (pre-SharePoint 2010))
    • Edited by tushartayal Friday, September 10, 2010 9:06 AM
    Friday, September 03, 2010 10:20 AM

Answers

  • Hi tushartayal,

     

    Welcome to MSDN Forums!

     

    1)       You could Make sure that you have created (new ) these object before you used them:

    ultraNumericUniqueID, ultraMaskedISOCode, ultraMaskedAlphaCode, ultraNumericNumCode, ultraMaskedName, ultraMaskedContinent.

     

    2)       I don’t know if the “BusinessObject” name is a type’s or an instance’s.

     

    You can do the following steps to debug your code and watch every member of this code to be sure they are run the right way.

    a)       Add a breakpoint at the start of your code. You can just double click the header of the row, or right click this row then add a breakpoint.

    b)      Press F5 to begin to debug this code.

    c)       The code will run and pause on the code line you added a breakpoint. Then you can move the mouse over the references and see their information, and then you can see if they had set to an instance or null.

    d)      Press F11 to let the code run into the next code line.

    e)       Do the things c) and d) to debug all the code you feel need to debug.

     

    With these steps you can find out the null reference, and then you could create this instance then use it. Or go on debugging to find out why the code cannot get the instance and find the root cause. Then you can find way through your application to get an instance.

     

     

    Best wishes,

    Mike

    -------------------------------------------------------------------

    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to the others community members reading the thread.

    Friday, September 10, 2010 2:04 AM
    Moderator

All replies

  • Can't see how this is a SharePoint related error.
    My SharePoint Blog - http://www.davehunter.co.uk/blog
    Friday, September 03, 2010 3:31 PM
  • Hi there,

    I think you have posted this in the wrong forum section. Search for MSDN forums and look through the categories to find out which one is best suitable for your requirements.

    Hope this helps,

    Thanks

    Friday, September 03, 2010 3:37 PM
  • Hi tushartayal,

     

    Welcome to MSDN Forums!

     

    1)       You could Make sure that you have created (new ) these object before you used them:

    ultraNumericUniqueID, ultraMaskedISOCode, ultraMaskedAlphaCode, ultraNumericNumCode, ultraMaskedName, ultraMaskedContinent.

     

    2)       I don’t know if the “BusinessObject” name is a type’s or an instance’s.

     

    You can do the following steps to debug your code and watch every member of this code to be sure they are run the right way.

    a)       Add a breakpoint at the start of your code. You can just double click the header of the row, or right click this row then add a breakpoint.

    b)      Press F5 to begin to debug this code.

    c)       The code will run and pause on the code line you added a breakpoint. Then you can move the mouse over the references and see their information, and then you can see if they had set to an instance or null.

    d)      Press F11 to let the code run into the next code line.

    e)       Do the things c) and d) to debug all the code you feel need to debug.

     

    With these steps you can find out the null reference, and then you could create this instance then use it. Or go on debugging to find out why the code cannot get the instance and find the root cause. Then you can find way through your application to get an instance.

     

     

    Best wishes,

    Mike

    -------------------------------------------------------------------

    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to the others community members reading the thread.

    Friday, September 10, 2010 2:04 AM
    Moderator
  • Reason forr NULLReferenceException:

    Reference type variables contain the memory address of objects in the heap. By default,when a reference type variable is created, it is initialized to null, indicating that the reference type variable doesn't currently point to a valid object. Attempting to use a null reference type variable causes a NullReferenceException to be thrown.


    Abhinav Galodha
    Friday, September 10, 2010 5:10 AM