Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old March 19th, 2007, 01:27 PM
Authorized User
 
Join Date: Jul 2006
Location: , , .
Posts: 21
Thanks: 0
Thanked 1 Time in 1 Post
Default 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;
    }

Reply With Quote
  #2 (permalink)  
Old March 20th, 2007, 12:39 AM
Friend of Wrox
 
Join Date: May 2006
Location: San Diego, CA, USA.
Posts: 643
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You must first make an instance of an object before you can use it.
In your case, yoiu actually need to instantiate 2 objects before you can attempt to use them (your tvret - which would be an instance of the TVReturn class, and its member amortization - which is an instance of a instance TVAmortizationSchedule class). You'll also need a way to make an instance of TVAmortizationData and put it into the "data" array that you are apparently trying to use as the only member of your TVAmortization class. You'll need a way to dimension the "data" array as well... or at least I think you will. Does this code compile? Apparently it does, but you have a little work to do before this will actually do anything.



Woody Z
http://www.learntoprogramnow.com
How to use a forum to help solve problems
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Null reference exception was unhandled labby C# 2005 0 April 24th, 2007 07:14 AM
Null Reference Exception was unhandled labby C# 2005 1 February 9th, 2007 03:15 PM
Null reference exception when using DataAdapter Samantha Karen Webb C# 1 July 21st, 2006 10:12 AM
NULL reference exception Dwizz VB.NET 2002/2003 Basics 3 June 21st, 2005 08:15 AM
Problems in ViewStates[]. Null Reference? chenzw BOOK: ASP.NET Website Programming Problem-Design-Solution 0 April 6th, 2004 09:01 PM



All times are GMT -4. The time now is 03:51 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.