An unhandled exception of type 'System.NullReferenceException' occurred

J

juli

Hello!
I keep getting this error:

An unhandled exception of type 'System.NullReferenceException' occurred
Additional information: Object reference not set to an instance of an object.

I am declaring with this code(class member):
private Steema.TeeChart.Styles.Series ASeries;

and than trying to initialize it:
this.ASeries.FillSampleValues();
Why do I get this error?
Thanks a lot!
 
R

Richard Blewett [DevelopMentor]

Basically when you are dealing with classes you have 2 separate tings to consider. The object allocated on the managed heap (created using the new operator) and the reference that refers to the object. What you have done is declare the reference (ASeries) but you have not created the object it is pointing at using new. Therefore it is taking its default value which is null.

Now you are calling a method via the reference, but the reference doesn't point to an object so you get a NullReferenceException.

Change tghe line where you declare ASeries to

private Steema.TeeChart.Styles.Series ASeries = new Steema.TeeChart.Styles.Series(); // this assumes it class has a default constructor

Regards

Richard Blewett - DevelopMentor
http://www.dotnetconsult.co.uk/weblog
http://www.dotnetconsult.co.uk

Hello!
I keep getting this error:

An unhandled exception of type 'System.NullReferenceException' occurred
Additional information: Object reference not set to an instance of an object.

I am declaring with this code(class member):
private Steema.TeeChart.Styles.Series ASeries;

and than trying to initialize it:
this.ASeries.FillSampleValues();
Why do I get this error?
Thanks a lot!
 
M

Morten Wennevik

Hi juli,

You get this error because you only declare a referense to a
Steema.TeeChart.Styles.Series object. This referenced (called ASeries) is
empty until you reference an object with it, so when you call
ASeries.FillSampleValues() there is nothing in ASeries that can do
anything and the exception is thrown.

Add this line:

ASeries = new Steema.TeeChart.Styles.Series();

I'm not familiar with the Series Steema namespace so you may need to
change the constructor and how the object is created (some objects cannot
be created by constructor).
 
C

Chris Ireland

Hi Juli,
ASeries = new Steema.TeeChart.Styles.Series();
I'm not familiar with the Series Steema namespace so you may need to
change the constructor and how the object is created (some objects cannot
be created by constructor).

The series object can be created this way but it is a base class and as
such will probably not be very useful to you. You might want to have a
go with simple working example such as this one:

Steema.TeeChart.Styles.Bar bar1 = new
Steema.TeeChart.Styles.Bar(tChart1.Chart);
bar1.FillSampleValues();

there are many more working examples for you to study in the features
demo and tutorials shipped with TeeChart.

Best Regards,
Christopher Ireland
Programmer
http://support.steema.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top