Object reference

S

simonZ

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
 
N

Nick

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?
 
T

Tasos Vogiatzoglou

Array indexes are zero based.

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

Regards,
Tasos
 
?

=?ISO-8859-1?Q?G=F6ran_Andersson?=

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.
 

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