Solved

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

Posted on 2014-01-29
7
971 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 

Author Comment

by:shanthi_joseph
Comment Utility
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
Comment Utility
I do not require a solution for this problem.
0
 

Author Closing Comment

by:shanthi_joseph
Comment Utility
I do not require a solution to this problem.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

744 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now