Solved

Obtained error: Object reference not set to an instance of an object.

Posted on 2014-01-29
7
990 Views
Last Modified: 2014-05-05
Server Error in '/' Application.
--------------------------------------------------------------------------------
drpRegions is set correctly but the 'Object reference not set to an instance of an object.' error is obtained

Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:


Line 550:        Dim plantRowItem As dsPlants.tblPlantsRow
Line 551:        For Each plantRowItem In dsPlants.tblPlants
Line 552:            If ((plantRowItem.RegionCode.ToString() = drpRegions.SelectedItem.Value.ToString()) _
Line 553:            And (plantRowItem.CellCode.ToString() = drpCells.SelectedItem.Value.ToString()) _
Line 554:            And ((drpPlants.SelectedIndex <> -1) And (plantRowItem.PlantName.ToString() = drpPlants.SelectedItem.Value.ToString())) _
 

Source File: C:\Inetpub\QSIRegister\QSIStage1.aspx.vb    Line: 552

Stack Trace:


[NullReferenceException: Object reference not set to an instance of an object.]
   ReadymixQSI_ASPNET.QSIStage1.SetMgrs() in C:\Inetpub\QSIRegister\QSIStage1.aspx.vb:552
   ReadymixQSI_ASPNET.QSIStage1.drpCells_SelectedIndexChanged(Object sender, EventArgs e) in C:\Inetpub\QSIRegister\QSIStage1.aspx.vb:601
   ReadymixQSI_ASPNET.QSIStage1.Page_Load(Object sender, EventArgs e) in C:\Inetpub\QSIRegister\QSIStage1.aspx.vb:290
   System.Web.UI.Control.OnLoad(EventArgs e) +131
   System.Web.UI.Control.LoadRecursive() +65
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2427

 


--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:2.0.50727.5448; ASP.NET Version:2.0.50727.5420
0
Comment
Question by:shanthi_joseph
7 Comments
 
LVL 18

Expert Comment

by:Dennis Aries
ID: 39821671
Several options come to mind here:
Is there a selected item?  Has the regioncode been set?

Assuming you cannot use breakpoints: for debugging,  create several helper variables and set them to the values you use.
That way you will see which item gives you the problem and add checks accordingly to overcome the issue.
0
 
LVL 22

Expert Comment

by:p_davis
ID: 39821677
you should still, probably, make sure to check that selecteditem has a value before referencing it.

drpRegions.SelectedItem.Value.ToString())
0
 
LVL 21

Expert Comment

by:Craig Wagner
ID: 39821766
As the other responders have indicated, there are several things in that line that could be null.

If ((plantRowItem.RegionCode.ToString() = drpRegions.SelectedItem.Value.ToString()) _

plantRowItem could be null
RegionCode could be null
drpRegions could be null
SelectedItem could be null
Value could be null

Use the debugger and check each of the above values to figure out which one of them is actually causing the exception.
0
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 

Author Comment

by:shanthi_joseph
ID: 39828637
I am not able to use object as a parameter in MsgBox. How do we check if the object is null?
0
 

Accepted Solution

by:
shanthi_joseph earned 0 total points
ID: 40033812
I do not require a solution for this problem.
0
 

Author Closing Comment

by:shanthi_joseph
ID: 40041609
I do not require a solution to this problem.
0

Featured Post

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question