By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,781 Members | 1,373 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,781 IT Pros & Developers. It's quick & easy.

Object reference

P: n/a
in global.asax file of my web application I defined:

public void Application_Start(Object sender, EventArgs e) {

String[] besedila = new String[2];

besedila[1] = "test";

Application["besedilo"] = besedila;

}

And then on my page I have:

public partial class objava : System.Web.UI.Page

{

protected void Page_Load(object sender, EventArgs e)

{

String test;
String[] besedila = new String[2];

besedila[1] = "test";
test = besedila[1].ToString();
}

}

And I get the following error:
Object reference not set to an instance of an object.

What that could be? Any idea?

Regards,S


May 19 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
You shouldn't need the .ToString() method because the array is already
of String type. That wouldn't cause the object reference error.

Which line is throwing this exception?

May 19 '06 #2

P: n/a
Array indexes are zero based.

Have you checked that Application object is different than null in
Application_Start ?

Regards,
Tasos

May 19 '06 #3

P: n/a
The code in global.asax and the code in the page are totally unrelated,
and I see nothing in either of them that would cause that exception. The
first item in both array that you create is null, as you don't give them
any value, but that is no problem as you don't use the first item of
either array.

On what line in what file do you get the exception?

simonZ wrote:
in global.asax file of my web application I defined:

public void Application_Start(Object sender, EventArgs e) {

String[] besedila = new String[2];

besedila[1] = "test";

Application["besedilo"] = besedila;

}

And then on my page I have:

public partial class objava : System.Web.UI.Page

{

protected void Page_Load(object sender, EventArgs e)

{

String test;
String[] besedila = new String[2];

besedila[1] = "test";
test = besedila[1].ToString();
}

}

And I get the following error:
Object reference not set to an instance of an object.

What that could be? Any idea?

Regards,S

May 19 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.