Saturday, March 24, 2012

Newbie having problems with a server error

I'm receiving the following server error when debugging my C# code:

"Object reference not set to an instance of an object."

I understand the error but can't see why it's happening. The line it refers to is:

<%Response.Write(Validate.setColour(errorcode[0]));%
The 'Validate' object is an instance of the following class:


using System;

namespace _4Touristweb
{
/// <summary>
/// Summary description for validate.
/// </summary>
public class validate
{
private string outputString;

public validate()
{
//
// TODO: Add constructor logic here
//
}

public string setColour(bool errorcode)
{
if (errorcode)
//set colour to red
outputString = "<DIV style=\"color:"+"#FF0000"+";\">";
else
//set colour to black
outputString = "<DIV style=\"color:"+"#000000"+";\">";

return outputString;
}
}
}

And in the HTML file I have this at the top, which creates the instance of the class.

<%@dotnet.itags.org. Page language="c#" Codebehind="reg2.aspx.cs" AutoEventWireup="false" Inherits="_4Touristweb.WebForm1" %>
<script runat="server" language="C#">
public bool[] errorcode;
public _4Touristweb.validate Validate = new _4Touristweb.validate();
public string businessName;
public string address;
public string district;
public string town;
public string postcode;
public string telephone;
public string fax;
public string county;
public string email;
public string contactName;
public bool terms;
</script
I'm afraid I haven't a clue why the error is coming up.Hi,

In this line <%Response.Write(Validate.setColour(errorcode[0]));%
What is the errorcode[0] value. Seems like there is no value to send to the Validate.setColour() Method.
Thanks for that 'heads up'. I forgot to create an instance of the boolean array in the declarations in the start.

Been a few years since I last did any serious OOP and it's showing.

0 comments:

Post a Comment