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

When would null pointer exception occurs ?

P: n/a
for (int i=0; i<_request.Form.Count; i++ )
{
string key = _request.Form.GetKey(i);
if ( !key.Equals("formCode")
&& !key.Equals("formLanguage")
&& !key.Equals("__VIEWSTATE")
&& !key.Equals("__EVENTARGUMENT")
&& !key.Equals("__EVENTTARGET")
&& key.IndexOf("sendButton")<0
&& key.IndexOf("clearButton")<0
&& key.IndexOf("HeaderControl")<0
&& key.IndexOf("PostingListControl")<0 )
{
formVO.addFormData(key,
StringUtil.extractStringFromStringArray(_request.F orm.GetValues(key)));
}
}

here is a part of my code. After several postback due to invalid validation,
null pointer exception is caught. What I wonder is request.Form.Count means
number of name-value pairs in Form collection. Then variable i would be
within the range of count. The null pointer exception seem to point to the
variable key. Is that possible a name-value pair can contain a null as key ?
Thx
Nov 19 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Look at the trace.axd to get more information and you will probably see
what's going wrong.

It is also possible that one of the key don't have an associated value.
This happens frequently with the QueryString information. You should store
the value of request.Form.GetValues(key) as an object and make that it's not
null before using it.

S. L.

"Tony Cheng" <sd***@fdfsds.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
for (int i=0; i<_request.Form.Count; i++ )
{
string key = _request.Form.GetKey(i);
if ( !key.Equals("formCode")
&& !key.Equals("formLanguage")
&& !key.Equals("__VIEWSTATE")
&& !key.Equals("__EVENTARGUMENT")
&& !key.Equals("__EVENTTARGET")
&& key.IndexOf("sendButton")<0
&& key.IndexOf("clearButton")<0
&& key.IndexOf("HeaderControl")<0
&& key.IndexOf("PostingListControl")<0 )
{
formVO.addFormData(key,
StringUtil.extractStringFromStringArray(_request.F orm.GetValues(key)));
}
}

here is a part of my code. After several postback due to invalid
validation, null pointer exception is caught. What I wonder is
request.Form.Count means number of name-value pairs in Form collection.
Then variable i would be within the range of count. The null pointer
exception seem to point to the variable key. Is that possible a name-value
pair can contain a null as key ? Thx

Nov 19 '05 #2

P: n/a
Where I can get the trace.axd ?
And also, the exception thrown from code lied in section

if ( !key.Equals("formCode")
&& !key.Equals("formLanguage")
&& !key.Equals("__VIEWSTATE")
&& !key.Equals("__EVENTARGUMENT")
&& !key.Equals("__EVENTTARGET")
&& key.IndexOf("sendButton")<0
&& key.IndexOf("clearButton")<0
&& key.IndexOf("HeaderControl")<0
&& key.IndexOf("PostingListControl")<0 )

the null pointer exception seem to point to variable key. That's why I asked
would it possible the key would be a null value ? Thx

"Sylvain Lafontaine" <sylvain aei ca (fill the blanks, no spam please)>
wrote in message news:OL**************@TK2MSFTNGP10.phx.gbl...
Look at the trace.axd to get more information and you will probably see
what's going wrong.

It is also possible that one of the key don't have an associated value.
This happens frequently with the QueryString information. You should
store the value of request.Form.GetValues(key) as an object and make that
it's not null before using it.

S. L.

"Tony Cheng" <sd***@fdfsds.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
for (int i=0; i<_request.Form.Count; i++ )
{
string key = _request.Form.GetKey(i);
if ( !key.Equals("formCode")
&& !key.Equals("formLanguage")
&& !key.Equals("__VIEWSTATE")
&& !key.Equals("__EVENTARGUMENT")
&& !key.Equals("__EVENTTARGET")
&& key.IndexOf("sendButton")<0
&& key.IndexOf("clearButton")<0
&& key.IndexOf("HeaderControl")<0
&& key.IndexOf("PostingListControl")<0 )
{
formVO.addFormData(key,
StringUtil.extractStringFromStringArray(_request.F orm.GetValues(key)));
}
}

here is a part of my code. After several postback due to invalid
validation, null pointer exception is caught. What I wonder is
request.Form.Count means number of name-value pairs in Form collection.
Then variable i would be within the range of count. The null pointer
exception seem to point to the variable key. Is that possible a
name-value pair can contain a null as key ? Thx


Nov 19 '05 #3

P: n/a
Tony:

Does this happen on a development machine? The quickest way to find
out the root of the problem is to use the debugger.

--
Scott
http://www.OdeToCode.com/blogs/scott/

On Tue, 22 Mar 2005 15:55:10 +0800, "Tony Cheng" <sd***@fdfsds.com>
wrote:
Where I can get the trace.axd ?
And also, the exception thrown from code lied in section

if ( !key.Equals("formCode")
&& !key.Equals("formLanguage")
&& !key.Equals("__VIEWSTATE")
&& !key.Equals("__EVENTARGUMENT")
&& !key.Equals("__EVENTTARGET")
&& key.IndexOf("sendButton")<0
&& key.IndexOf("clearButton")<0
&& key.IndexOf("HeaderControl")<0
&& key.IndexOf("PostingListControl")<0 )

the null pointer exception seem to point to variable key. That's why I asked
would it possible the key would be a null value ? Thx

"Sylvain Lafontaine" <sylvain aei ca (fill the blanks, no spam please)>
wrote in message news:OL**************@TK2MSFTNGP10.phx.gbl...
Look at the trace.axd to get more information and you will probably see
what's going wrong.

It is also possible that one of the key don't have an associated value.
This happens frequently with the QueryString information. You should
store the value of request.Form.GetValues(key) as an object and make that
it's not null before using it.

S. L.

"Tony Cheng" <sd***@fdfsds.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
for (int i=0; i<_request.Form.Count; i++ )
{
string key = _request.Form.GetKey(i);
if ( !key.Equals("formCode")
&& !key.Equals("formLanguage")
&& !key.Equals("__VIEWSTATE")
&& !key.Equals("__EVENTARGUMENT")
&& !key.Equals("__EVENTTARGET")
&& key.IndexOf("sendButton")<0
&& key.IndexOf("clearButton")<0
&& key.IndexOf("HeaderControl")<0
&& key.IndexOf("PostingListControl")<0 )
{
formVO.addFormData(key,
StringUtil.extractStringFromStringArray(_request.F orm.GetValues(key)));
}
}

here is a part of my code. After several postback due to invalid
validation, null pointer exception is caught. What I wonder is
request.Form.Count means number of name-value pairs in Form collection.
Then variable i would be within the range of count. The null pointer
exception seem to point to the variable key. Is that possible a
name-value pair can contain a null as key ? Thx



Nov 19 '05 #4

P: n/a
You open a new browser window and you replace the name of the aspx file with
trace.axd. For exemple, if you asp.net file is
http://localhost/LxpNet1/Lxp7_Infrag.../welcome.aspx; then the new name
will be http://localhost/LxpNet1/Lxp7_Infragistic1/trace.axd .

Here are the parameters that I'm using in the web.config file:
<trace enabled="true" requestLimit="10" pageOutput="false"
traceMode="SortByTime" localOnly="true" />

If pageOutput is set to true instead of false, the output of the trace will
get mixed with the HTML written by the aspx file; clearly something that you
don't want must of the time. You can also use Trace.Write (...) and
Trace.Warn (...) to output data to the trace file.

S. L.

"Tony Cheng" <sd***@fdfsds.com> wrote in message
news:uY**************@TK2MSFTNGP15.phx.gbl...
Where I can get the trace.axd ?
And also, the exception thrown from code lied in section

if ( !key.Equals("formCode")
&& !key.Equals("formLanguage")
&& !key.Equals("__VIEWSTATE")
&& !key.Equals("__EVENTARGUMENT")
&& !key.Equals("__EVENTTARGET")
&& key.IndexOf("sendButton")<0
&& key.IndexOf("clearButton")<0
&& key.IndexOf("HeaderControl")<0
&& key.IndexOf("PostingListControl")<0 )

the null pointer exception seem to point to variable key. That's why I
asked would it possible the key would be a null value ? Thx

"Sylvain Lafontaine" <sylvain aei ca (fill the blanks, no spam please)>
wrote in message news:OL**************@TK2MSFTNGP10.phx.gbl...
Look at the trace.axd to get more information and you will probably see
what's going wrong.

It is also possible that one of the key don't have an associated value.
This happens frequently with the QueryString information. You should
store the value of request.Form.GetValues(key) as an object and make that
it's not null before using it.

S. L.

"Tony Cheng" <sd***@fdfsds.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
for (int i=0; i<_request.Form.Count; i++ )
{
string key = _request.Form.GetKey(i);
if ( !key.Equals("formCode")
&& !key.Equals("formLanguage")
&& !key.Equals("__VIEWSTATE")
&& !key.Equals("__EVENTARGUMENT")
&& !key.Equals("__EVENTTARGET")
&& key.IndexOf("sendButton")<0
&& key.IndexOf("clearButton")<0
&& key.IndexOf("HeaderControl")<0
&& key.IndexOf("PostingListControl")<0 )
{
formVO.addFormData(key,
StringUtil.extractStringFromStringArray(_request.F orm.GetValues(key)));
}
}

here is a part of my code. After several postback due to invalid
validation, null pointer exception is caught. What I wonder is
request.Form.Count means number of name-value pairs in Form collection.
Then variable i would be within the range of count. The null pointer
exception seem to point to the variable key. Is that possible a
name-value pair can contain a null as key ? Thx



Nov 19 '05 #5

P: n/a
thx so much

"Sylvain Lafontaine" <sylvain aei ca (fill the blanks, no spam please)>
wrote in message news:u7**************@TK2MSFTNGP14.phx.gbl...
You open a new browser window and you replace the name of the aspx file
with trace.axd. For exemple, if you asp.net file is
http://localhost/LxpNet1/Lxp7_Infrag.../welcome.aspx; then the new name
will be http://localhost/LxpNet1/Lxp7_Infragistic1/trace.axd .

Here are the parameters that I'm using in the web.config file:
<trace enabled="true" requestLimit="10" pageOutput="false"
traceMode="SortByTime" localOnly="true" />

If pageOutput is set to true instead of false, the output of the trace
will get mixed with the HTML written by the aspx file; clearly something
that you don't want must of the time. You can also use Trace.Write (...)
and Trace.Warn (...) to output data to the trace file.

S. L.

"Tony Cheng" <sd***@fdfsds.com> wrote in message
news:uY**************@TK2MSFTNGP15.phx.gbl...
Where I can get the trace.axd ?
And also, the exception thrown from code lied in section

if ( !key.Equals("formCode")
&& !key.Equals("formLanguage")
&& !key.Equals("__VIEWSTATE")
&& !key.Equals("__EVENTARGUMENT")
&& !key.Equals("__EVENTTARGET")
&& key.IndexOf("sendButton")<0
&& key.IndexOf("clearButton")<0
&& key.IndexOf("HeaderControl")<0
&& key.IndexOf("PostingListControl")<0 )

the null pointer exception seem to point to variable key. That's why I
asked would it possible the key would be a null value ? Thx

"Sylvain Lafontaine" <sylvain aei ca (fill the blanks, no spam please)>
wrote in message news:OL**************@TK2MSFTNGP10.phx.gbl...
Look at the trace.axd to get more information and you will probably see
what's going wrong.

It is also possible that one of the key don't have an associated value.
This happens frequently with the QueryString information. You should
store the value of request.Form.GetValues(key) as an object and make
that it's not null before using it.

S. L.

"Tony Cheng" <sd***@fdfsds.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
for (int i=0; i<_request.Form.Count; i++ )
{
string key = _request.Form.GetKey(i);
if ( !key.Equals("formCode")
&& !key.Equals("formLanguage")
&& !key.Equals("__VIEWSTATE")
&& !key.Equals("__EVENTARGUMENT")
&& !key.Equals("__EVENTTARGET")
&& key.IndexOf("sendButton")<0
&& key.IndexOf("clearButton")<0
&& key.IndexOf("HeaderControl")<0
&& key.IndexOf("PostingListControl")<0 )
{
formVO.addFormData(key,
StringUtil.extractStringFromStringArray(_request.F orm.GetValues(key)));
}
}

here is a part of my code. After several postback due to invalid
validation, null pointer exception is caught. What I wonder is
request.Form.Count means number of name-value pairs in Form collection.
Then variable i would be within the range of count. The null pointer
exception seem to point to the variable key. Is that possible a
name-value pair can contain a null as key ? Thx



Nov 19 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.