Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2014-01-29
7
Medium Priority
?
1,004 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

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

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

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

It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

618 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