?
Solved

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

Posted on 2014-01-29
7
Medium Priority
?
1,001 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
What Is Blockchain Technology?

Blockchain is a technology that underpins the success of Bitcoin and other digital currencies, but it has uses far beyond finance. Learn how blockchain works and why it is proving disruptive to other areas of IT.

 

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

CHALLENGE LAB: Troubleshooting Connectivity Issues

Goal: Fix the connectivity issue in the lab's AWS environment so that you can SSH into the provided EC2 instance.  

Question has a verified solution.

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

Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses
Course of the Month12 days, 22 hours left to enroll

777 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