473,320 Members | 1,744 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

NullReferenceException - Object reference not set to an instance of an object ASP.NET

Im getting a NullReferenceException when I goto add a product to my cart, i get the error when i come to this part

Expand|Select|Wrap|Line Numbers
  1. cart.AddProduct(productnumber, name, price, prodQty, knobColor, finishColor)
I use extremely similar code in another one of my projects and do not come across this problem, I have also researched it for a while and still came across no soltuion.

Expand|Select|Wrap|Line Numbers
  1. Protected Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
  2.  
  3.         Dim cart As New Cart
  4.         cart = Session("Cart")
  5.  
  6.  
  7.         Dim flag As Integer = 1
  8.         Dim finishColor As String = ""
  9.         Dim knobColor As String = ""
  10.         Dim prodQty As Integer = 0
  11.         Dim price As Decimal = 0
  12.         Dim name As String = ""
  13.         Dim productnumber As Integer = 0
  14.  
  15.         If txtQty.Text = "" Then
  16.             lblError.Text = "Please enter a numeric quantity."
  17.         ElseIf Not IsNumeric(txtQty.Text) Then
  18.             lblError.Text = "Please enter a numeric quantity."
  19.             Return
  20.         ElseIf Not Integer.Parse(txtQty.Text) > 0 Then
  21.             lblError.Text = "Please enter a integer numeric quantity."
  22.             Return
  23.         End If
  24.  
  25.         If Not txtQty.Text = "" Then
  26.             productnumber = prodID
  27.             name = lblName.Text
  28.             price = lblPrice.Text
  29.             prodQty = txtQty.Text
  30.             finishColor = DDFinish.SelectedItem.Text
  31.             knobColor = DDKnob.SelectedItem.Text
  32.  
  33.             cart.AddProduct(productnumber, name, price, prodQty, knobColor, finishColor)
  34.  
  35.  
  36.         End If
  37.  
  38.         Session("Cart") = cart
class that this sends to
Expand|Select|Wrap|Line Numbers
  1. cart.AddProduct(productnumber, name, price, prodQty, knobColor, finishColor)
:

Expand|Select|Wrap|Line Numbers
  1.  <Serializable()> Public Class Cart
  2.     Dim Prods As New ArrayList
  3.  
  4.     Public Sub AddProduct(ByVal _ProductNumber As Integer, ByVal _Name As String, ByVal _Price As Decimal, ByVal _Quantity As Integer, ByVal _knob As String, ByVal _finish As String)
  5.         Dim Item As New ProductClass2
  6.         Item.pID = _ProductNumber
  7.         Item.Name = _Name
  8.         Item.Price = _Price
  9.         Item.Quantity = _Quantity
  10.         Item.Knob = _knob
  11.         Item.Finish = _finish
  12.  
  13.         Prods.Add(Item)
  14.     End Sub
Apr 10 '08 #1
1 1086
DrBunchman
979 Expert 512MB
Hi firebirds98,

If you add a break point on the line where you call AddProduct do all the variables that you are pass to the sub have a value?

Is it actually this line that's causing the exception or can you step inside the sub and find the line inside it that's causing the error?

By the way, you've posted your question in the Classic ASP forum. As you are obviously working with ASP.NET please post all future questions in the .NET forum where you'll receive better help.

Dr B
Apr 11 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Terrence | last post by:
I am doing some of the C# walkthroughs to transition from VB to C#. When I try to execute static void Main() { Aplication.Run(new Form1()) } I raise a 'System.NullReferenceException" in...
7
by: mike p. | last post by:
I have a docbook xml file, and am using standard docbook 1.61.3 xsl stylesheets to do xhtml transform. Transform works fine when using MSXML. When I try to do the following using asp.net 1.1: ...
0
by: muralidharan | last post by:
WebForm1.aspx Code: <%@ Register TagPrefix="ComponentArt" Namespace="ComponentArt.Web.UI" Assembly="ComponentArt.Web.UI" %> <ComponentArt:TreeView id="TreeView1" Height="520"...
2
by: Raed Sawalha | last post by:
i have a windows form(Main) with listview, when click an item in listview i open other window form (Sub) which generate the selected item from parent window in as treeview items when click any item...
1
by: msnews.microsoft.com | last post by:
I'm trying to fill an array of objects but when I add the first object I get a NullReferenceException. ----------------------------------------------------------------------------...
2
by: sxiao | last post by:
Hi, there I got a NullReferenceException when there are more than one users trying to open the same page at the same time. The senerio is: Two users logged into the web application using the...
6
by: William Mild | last post by:
I must be getting brain fried. I can't see the error. Create a new web form with the following code begind: Public Class test Inherits System.Web.UI.Page Public Class ReportCardData ...
1
by: Craig | last post by:
This is killing me, I've been trying to figure this out for 2 days. When I click on the linkbutton, it executes the GetData(int) method to set the DataSource. The FAILURE is when it tries to...
0
by: sqlguy | last post by:
I am using a vendor package written in .net 2.0 C#. They say it works well, and that I may have a configuration issue. The error I am getting is shown below. Searching ms and google, it seems...
7
by: Zytan | last post by:
I just got the strangest error. I have exception code that catches a null reference exception: catch (NullReferenceException ex) { ... } The handling code does nothing but print out data from...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.