C Board  

Go Back   C Board > General Programming Boards > C# Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 11-24-2008, 11:06 PM   #1
Registered User
 
Join Date: Nov 2008
Posts: 34
Question Nullreference exception

hi all

i have errors while bulding the code in c#

Code:
 private void subMenuModify_Click(object sender, System.EventArgs e)
        {
            int nStart = X;
            int spos = 0;
            int epos = this.lvFiles.Columns[0].Width;
            for (int i = 0; i < this.lvFiles.Columns.Count; i++)
            {
                if (nStart > spos && nStart < epos)
                {
                    subItemSelected = i;
                    break;
                }

                spos = epos;
                epos += this.lvFiles.Columns[i].Width;
            }
            subItemText = this.lvItem.SubItems[2].Text;
the line at which exception occurs is subItemText = this.lvItem.SubItems[2].Text;

the exception is as follows:


Nullreference exception was unhandled

Object reference not set to an instance of an object.


Pls anyone help me resolve this issue?
leo2008 is offline   Reply With Quote
Old 11-24-2008, 11:10 PM   #2
Registered User
 
valaris's Avatar
 
Join Date: Jun 2008
Location: RING 0
Posts: 468
Looks like that item doesn't exist in your menu. Make sure there are at least 3 items in your menu or that will not work.
valaris is offline   Reply With Quote
Old 11-24-2008, 11:46 PM   #3
Registered User
 
Join Date: Nov 2008
Posts: 34
Question

which item do you think is missing here? u mean "modify item"?
leo2008 is offline   Reply With Quote
Old 11-24-2008, 11:54 PM   #4
Registered User
 
valaris's Avatar
 
Join Date: Jun 2008
Location: RING 0
Posts: 468
Code:
subItemText = this.lvItem.SubItems[2].Text;
This indexer tries to access something that doesn't exist probably. Make sure you have 3 items at least in this collection. It's usually not good to address menu's in this order unless you are guaranteed to have something there, otherwise you can get exceptions like this.
valaris is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Exception handling in a large project EVOEx C++ Programming 7 01-25-2009 07:33 AM
exception handling coletek C++ Programming 2 01-12-2009 05:28 PM
Handle C++ exception and structured exception together George2 C++ Programming 2 01-24-2008 09:21 PM
Signal and exception handling nts C++ Programming 23 11-15-2007 02:36 PM
Problem with the exception class in MINGW indigo0086 C++ Programming 6 01-20-2007 01:12 PM


All times are GMT -6. The time now is 09:24 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22