473,473 Members | 1,483 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Null reference issue

Hi,

I am having a problem of storing a string into
TVReturn.amortization.data[0].balanceAmount (class definitions are
given below), where I get the error message saying:
System.NullReferenceException: Object reference not set to an instance
of an object

at this line where I am testing inserting values into the amortization
schedule data

tvret.amortization.data[0].balanceAmount =
Convert.ToDecimal("100000");
I have the following class definitions:

public class TVReturn
{
public decimal unknownEventAmount;
public double unknownNominalAnnualRate;
public int unknownEventNumber;
public string cashFlowDataXml;
public TVAmortizationSchedule amortization;
}

public class TVAmortizationSchedule
{
public TVAmortizationData[] data;
}

public class TVAmortizationData
{
public int sequenceNumber;
public string eventDate;
public decimal paymentAmount;
public decimal interestAmount;
public decimal principalAmount;
public decimal balanceAmount;
}

Mar 19 '07 #1
4 1172
Have you tried adding a function to check items for nulls and then, return
whatever you want, in case it's actually null?
Something like:
tvret.amortization.data[0].balanceAmount =
CheckForNull(Convert.ToDecimal("100000"));
David Wier
MVP/ASPInsider
http://aspnet101.com
http://aspexpress.com

"Raul" <al******@gmail.comwrote in message
news:11**********************@o5g2000hsb.googlegro ups.com...
Hi,

I am having a problem of storing a string into
TVReturn.amortization.data[0].balanceAmount (class definitions are
given below), where I get the error message saying:
System.NullReferenceException: Object reference not set to an instance
of an object

at this line where I am testing inserting values into the amortization
schedule data

tvret.amortization.data[0].balanceAmount =
Convert.ToDecimal("100000");
I have the following class definitions:

public class TVReturn
{
public decimal unknownEventAmount;
public double unknownNominalAnnualRate;
public int unknownEventNumber;
public string cashFlowDataXml;
public TVAmortizationSchedule amortization;
}

public class TVAmortizationSchedule
{
public TVAmortizationData[] data;
}

public class TVAmortizationData
{
public int sequenceNumber;
public string eventDate;
public decimal paymentAmount;
public decimal interestAmount;
public decimal principalAmount;
public decimal balanceAmount;
}

Mar 19 '07 #2
On Mar 19, 2:36 pm, "David Wier" <david_w...@noSpamhotmail.comwrote:
Have you tried adding a function to check items for nulls and then, return
whatever you want, in case it's actually null?
Something like:
tvret.amortization.data[0].balanceAmount =
CheckForNull(Convert.ToDecimal("100000"));

Well, no I havent done so yet. Currently I am telling it to store
100000, so the value is definitely not null. I get the feeling that
the amortization object is not being instantiated. Even if I create a
test member, tvret.amortization.test = "100000" then I get the same
message.

Mar 19 '07 #3
On Mar 19, 7:36 pm, "David Wier" <david_w...@noSpamhotmail.comwrote:
Have you tried adding a function to check items for nulls and then, return
whatever you want, in case it's actually null?
Something like:
tvret.amortization.data[0].balanceAmount =
CheckForNull(Convert.ToDecimal("100000"));

David Wier
MVP/ASPInsider
Wow!

Mar 19 '07 #4
On Mar 19, 6:43 pm, "Raul" <aljam...@gmail.comwrote:
On Mar 19, 2:36 pm, "David Wier" <david_w...@noSpamhotmail.comwrote:
Have you tried adding a function to check items for nulls and then, return
whatever you want, in case it's actually null?
Something like:
tvret.amortization.data[0].balanceAmount =
CheckForNull(Convert.ToDecimal("100000"));

Well, no I havent done so yet. Currently I am telling it to store
100000, so the value is definitely not null. I get the feeling that
the amortization object is not being instantiated. Even if I create a
test member, tvret.amortization.test = "100000" then I get the same
message.

TVReturn tvret = new TVReturn();
tvret.amortization = new TVAmortizationSchedule();
tvret.amortization.data = new TVAmortizationData[1]; // or what ever
tvret.amortization.data[0] = new TVAmortizationData();
tvret.amortization.data[0].balanceAmount =
Convert.ToDecimal("100000");

Mar 19 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: A.M. de Jong | last post by:
Reading a lot about Nulls right now I still can't find a Technical reason to use it or not. For what I've understand is this: In an Ingres database a Null column has a standard extra storage...
0
by: Shannon | last post by:
I am having a very stange issue happen to my web application. I am trying to develop a simple shopping cart. The code works perfectly when I run the application under http://localhost/myapp. ...
3
by: iStrain | last post by:
Hiya. I'm _sure_ this is an FAQ, but Googling hasn't produced the answer in a way I can make sense out of. I know I should get this, but so far no way... I'm creating tables and doing queries in...
102
by: junky_fellow | last post by:
Can 0x0 be a valid virtual address in the address space of an application ? If it is valid, then the location pointed by a NULL pointer is also valid and application should not receive "SIGSEGV"...
7
by: Dan | last post by:
I'm fairly new to C# and I am having some problems understanding int variables and null values. I have created a class that populates the values of it's fields from a DataReader in it's...
9
by: Steve Sargent | last post by:
Hi: I'm trying to debug the following code, and it keeps looping on the if statement: public static bool operator == (OnlineMemberNode first, OnlineMemberNode second) { if(first == null) {
22
by: Vagif Abilov | last post by:
We have several Web projects where we suddenly began experiencing various problems after porting them to .NET 2.0. I debugged one of them and here's what I've found: In one of referenced...
4
by: Joseph Geretz | last post by:
We use a Soap Header to pass a token class (m_Token) back and forth with authenticated session information. Given the following implementation for our Logout method, I vastly prefer to simply code...
2
by: Manikandan | last post by:
Hi, I have a table with following data Tablename:details No(varchar) Name(varchar) Updated(Datetime) 1 mm 10/10/2006 2 nn 02/12/2005 3 kk NULL I'm using executescalar to get the...
76
by: valentin tihomirov | last post by:
As explained in "Using pointers vs. references" http://groups.google.ee/group/borland.public.delphi.objectpascal/browse_thread/thread/683c30f161fc1e9c/ab294c7b02e8faca#ab294c7b02e8faca , the...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.