Link to home
Start Free TrialLog in
Avatar of homeshopper
homeshopperFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Object reference not set to an instance of an object.

I am getting following error: Object reference not set to an instance of an object
strArrayDB33[intDetail] = "AdminDB2";//line 129 Object reference not set to an instance of an object.
Thankyou in advance for any help given.
Full code as per attached snippet.
tempScript0.txt
Avatar of Nice-Ghaza
Nice-Ghaza
Flag of Libya image

Some Thing Wrong because Virus File .install the Antivirus Latest one
ASKER CERTIFIED SOLUTION
Avatar of Paul Jackson
Paul Jackson
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of homeshopper

ASKER

Thankyou for your comments. If I delete following code it works:
strArrayDB33 = (String[])Session["strArrayDB33"];
strArrayDetail33 = (String[])Session["strArrayDetail33"];
strArrayTable33 = (String[])Session["strArrayTable33"];
But, this now creates a new problem.
Elsewhere the elements/index of the array are incremented.
Then when it returns it does display the contents of the selected element of the array.
strArrayDB33 where i is the incremented element.
for example strArrayDB33[3]
But, now elements 0 to 2 are destroyed.
How can I preserve all other contents of the array?
Make sure that you have created array with required size and make sure that you ADDED properly before increment the value.

say for example:

string[] myArr = new string[3];
myArr[0] = "one";
myArr[1] = "two";
myArr[2] = "three";

Open in new window

yes, I understand what you say. Code Below:
protected string[] strArrayDB33 = new string[11];
protected string[] strArrayDetail33 = new string[11];
protected string[] strArrayTable33 = new string[11];
    protected void Page_Load(object sender, EventArgs e)
    {
    }
I have the following at the end of the code block:
for (var j = 0; j <= 10; j++)
            {
                Response.Write("(" + Convert.ToChar(j + 65) + ")" + strArrayDetail33[j] + "#&nbsp;&nbsp;Tab:" + "<a href='../scriptFrame/tempScript" + (currentPage).ToString() + ".aspx?db22=" + strArrayDB33[j] + "&dt22=" + strArrayTable33[j] + "&intDetail22=" + j + "&strD22=False" + "&PageID=" + (currentPage).ToString() + " ' title='" + strArrayTable33[j] + "' runat='server'>" + "<font color='#0000FF' size='1'>" + strArrayTable33[j] + "</font>" + "</a>#<br/>");
            }
            //********************************************************
            Session["strArrayDB33"] = strArrayDB33;
            Session["strArrayDetail33"] = strArrayDetail33;
            Session["strArrayTable33"] = strArrayTable33;
            Session["strIntDetail22"] = intstrDetail22;
        }
The following is displayed:
(A)#  Tab:#
(B)#  Tab:#
(C)#  Tab:#
(D)Data Source=dinosaur1;User ID=sa;Password=sasa; Initial Catalog=Cams2#  Tab:tblLinks#
(E)#  Tab:#
(F)#  Tab:#
(G)#  Tab:#
(H)#  Tab:#
(I)#  Tab:#
(J)#  Tab:#
(K)#  Tab:#
It displays the contents of the array at element [3] (D)
but contents in [0], [1], [2] or (A), (B), (C) are lost.
So that is why I put the following at the beginning of the code block,
to try and preserve all contents. But, then it causes the original error.
Thanks in advance for any help given.
public void BindData0()
    {
        try
        {
            strArrayDB33 = (String[])Session["strArrayDB33"];
            strArrayDetail33 = (String[])Session["strArrayDetail33"];
            strArrayTable33 = (String[])Session["strArrayTable33"];
I have now managed to display the following:
(A)Data Source=dinosaur1;User ID=sa;Password=sasa; Initial Catalog=AdminDB2#  Tab:AdminTable#
(B)Data Source=dinosaur1;User ID=sa;Password=sasa; Initial Catalog=pubs#  Tab:employee#
(C)Data Source=dinosaur1;User ID=sa;Password=sasa; Initial Catalog=Northwind#  Tab:Customers#
(D)Data Source=dinosaur1;User ID=sa;Password=sasa; Initial Catalog=Cams2#  Tab:tblFavourites#
(E)Data Source=dinosaur1;User ID=sa;Password=sasa; Initial Catalog=Cams2#  Tab:vw_ModSub_Sorted#
(F)Data Source=dinosaur1;User ID=sa;Password=sasa; Initial Catalog=Northwind#  Tab:Employees#
(G)Data Source=dinosaur1;User ID=sa;Password=sasa; Initial Catalog=Cams2#  Tab:tblRole#
(H)#  Tab:#
(I)#  Tab:#
(J)#  Tab:#
(K)#  Tab:#
I thought I'll test the Session["strArrayDB33"] for 'Null'
as it was previously suggested. It now all works by adding the following:
public void BindData0()
    {
        try
        {
            if (Session["strArrayDB33"] == null)
            {

            }
            else
            {
                strArrayDB33 = (String[])Session["strArrayDB33"];
                strArrayDetail33 = (String[])Session["strArrayDetail33"];
                strArrayTable33 = (String[])Session["strArrayTable33"];
            }