Solved

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

Posted on 2014-01-29
7
984 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
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 

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

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)

Question has a verified solution.

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

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
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…
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.

863 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

24 Experts available now in Live!

Get 1:1 Help Now