E
Eric A. Johnson
For the following code:
' return String representation of CTriangleShape
Public Overrides Function ToString() As String
' use MyBase reference to return CShape String
Return MyBase.ToString & ";" & vbCrLf & _
"Size of sides: " & mSideLength(0).ToString '& _
' ", " & mSideLength(1).ToString & ", " & _
' ", and " & mSideLength(2).ToString
End Function ' ToString
I get this error:
An unhandled exception of type 'System.NullReferenceException' occurred in
ShapeLibrary.exe
Additional information: Object reference not set to an instance of an
object.
.... I have tested it, and discovered that it is the mSideLength(0, 1, or 2)
sections that are causing the error, not any other portion. The problem is,
I wish to display each of the side lengths within the ToString function.
The mSideLength array is declared like so:
' Array containing the length of each side
Private mSideLength As Integer()
and instantiated thusly:
' constructor for scalene triangle
Public Sub New(ByVal side1 As Integer, _
ByVal side2 As Integer, ByVal side3 As Integer)
MyBase.New(mSides)
mSideLength = New Integer(mSides - 1) _
{side1, side2, side3}
Console.WriteLine("CTriangle constructor: {0}", Me)
End Sub ' New scalene triangle
....where mSides is the number of sides of the shape. Since it is a
triangle, this is of course 3 sides. Can anyone help me figure out why it
doesn't seem to want to display the side lengths? I have already, as you
can see, given it side lengths; if you can explain to me why it claims that
the object reference is not set to an instance of an object, when it seems
clear to me that mSideLength is clearly an instance of an Integer object (as
demonstrated by the New function), I would appreciate it greatly. I would
appreciate it even more if you can help me to understand how to fix this
problem! Thanks for your help.
-- Eric
' return String representation of CTriangleShape
Public Overrides Function ToString() As String
' use MyBase reference to return CShape String
Return MyBase.ToString & ";" & vbCrLf & _
"Size of sides: " & mSideLength(0).ToString '& _
' ", " & mSideLength(1).ToString & ", " & _
' ", and " & mSideLength(2).ToString
End Function ' ToString
I get this error:
An unhandled exception of type 'System.NullReferenceException' occurred in
ShapeLibrary.exe
Additional information: Object reference not set to an instance of an
object.
.... I have tested it, and discovered that it is the mSideLength(0, 1, or 2)
sections that are causing the error, not any other portion. The problem is,
I wish to display each of the side lengths within the ToString function.
The mSideLength array is declared like so:
' Array containing the length of each side
Private mSideLength As Integer()
and instantiated thusly:
' constructor for scalene triangle
Public Sub New(ByVal side1 As Integer, _
ByVal side2 As Integer, ByVal side3 As Integer)
MyBase.New(mSides)
mSideLength = New Integer(mSides - 1) _
{side1, side2, side3}
Console.WriteLine("CTriangle constructor: {0}", Me)
End Sub ' New scalene triangle
....where mSides is the number of sides of the shape. Since it is a
triangle, this is of course 3 sides. Can anyone help me figure out why it
doesn't seem to want to display the side lengths? I have already, as you
can see, given it side lengths; if you can explain to me why it claims that
the object reference is not set to an instance of an object, when it seems
clear to me that mSideLength is clearly an instance of an Integer object (as
demonstrated by the New function), I would appreciate it greatly. I would
appreciate it even more if you can help me to understand how to fix this
problem! Thanks for your help.
-- Eric