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

Null vs undefined

P: n/a
I have a structure (which happens to be a Java DataBean that contains some
string arrays) that is giving me an error.

The error at the "for" statement is:

Object reference not set to an instance of an object.

Here is the code where chDataBean is the structure.
chDataBean.voucherNumber is a string array of voucher numbers. But if there
are no numbers the debugger shows it as <undefined value>. But other fields
are showing as null in the debugger. What is the difference? How would I
test for each one? I assume I would have to do a test before the "for"
statement, since that is where I am getting the error.
************************************************** *************
chDataBean = checkHistoryService.readCheckHistory(
elDataBean.employeeIds[ktr],
ruDataBean.employerList[1][0],
"2006",
Session.SessionID);

for(ktr1=0;ktr1<= chDataBean.voucherNumber.GetUpperBound(0);ktr1++)
{
GetPayStatementData(ref sCheckLine,objStreamWriter,
elDataBean.employeeIds[ktr],chDataBean.voucherNumber[ktr1],chDataBean.payDate[ktr1],
ruDataBean.employerList[1][0],eDataBean);
}
************************************************** **********************

Thanks,

Tom
Apr 18 '06 #1
Share this Question
Share on Google+
6 Replies


P: n/a
tshad <ts**********@ftsolutions.com> wrote:
I have a structure (which happens to be a Java DataBean that contains some
string arrays) that is giving me an error.

The error at the "for" statement is:

Object reference not set to an instance of an object.

Here is the code where chDataBean is the structure.
chDataBean.voucherNumber is a string array of voucher numbers. But if there
are no numbers the debugger shows it as <undefined value>. But other fields
are showing as null in the debugger. What is the difference? How would I
test for each one? I assume I would have to do a test before the "for"
statement, since that is where I am getting the error.


They're the same thing - I don't know why the debugger shows them
differently, although it might be that it shows local variables which
have been assigned a value as null, but local variables which just
haven't been assigned yet as "undefined value".

Comparing with null would be better in either case.

By the way - if your array is a one-dimensional one, using
GetUpperBound is a bit messy compared with:

for (ktr1=0; ktr1 < chDataBean.voucherNumber.Length; ktr1++)

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Apr 18 '06 #2

P: n/a
Hi,
They're the same thing - I don't know why the debugger shows them
differently, although it might be that it shows local variables which
have been assigned a value as null, but local variables which just
haven't been assigned yet as "undefined value".

I think that both the debugger and the intellisense display <undefined
value> instead of null either way
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
Apr 18 '06 #3

P: n/a

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
tshad <ts**********@ftsolutions.com> wrote:
I have a structure (which happens to be a Java DataBean that contains
some
string arrays) that is giving me an error.

The error at the "for" statement is:

Object reference not set to an instance of an object.

Here is the code where chDataBean is the structure.
chDataBean.voucherNumber is a string array of voucher numbers. But if
there
are no numbers the debugger shows it as <undefined value>. But other
fields
are showing as null in the debugger. What is the difference? How would
I
test for each one? I assume I would have to do a test before the "for"
statement, since that is where I am getting the error.
They're the same thing - I don't know why the debugger shows them
differently, although it might be that it shows local variables which
have been assigned a value as null, but local variables which just
haven't been assigned yet as "undefined value".

Comparing with null would be better in either case.


Great.
By the way - if your array is a one-dimensional one, using
GetUpperBound is a bit messy compared with:

for (ktr1=0; ktr1 < chDataBean.voucherNumber.Length; ktr1++)
Why?

Tom
--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too

Apr 18 '06 #4

P: n/a

"Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us> wrote
in message news:%2****************@TK2MSFTNGP02.phx.gbl...
Hi,
They're the same thing - I don't know why the debugger shows them
differently, although it might be that it shows local variables which
have been assigned a value as null, but local variables which just
haven't been assigned yet as "undefined value".

I think that both the debugger and the intellisense display <undefined
value> instead of null either way


Actually, I am looking at a structure and am getting something like:
field1 null
field2 null
field3 null
field4 <undefined value>
field4 <undefined value>
field3 null
field4 <undefined value>
field3 null
field4 <undefined value>
....

Tom
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

Apr 18 '06 #5

P: n/a
tshad <ts**********@ftsolutions.com> wrote:
By the way - if your array is a one-dimensional one, using
GetUpperBound is a bit messy compared with:

for (ktr1=0; ktr1 < chDataBean.voucherNumber.Length; ktr1++)


Why?


Because it's easier to read (and write) .Length than .GetUpperBound(0).

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Apr 18 '06 #6

P: n/a
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
tshad <ts**********@ftsolutions.com> wrote:
> By the way - if your array is a one-dimensional one, using
> GetUpperBound is a bit messy compared with:
>
> for (ktr1=0; ktr1 < chDataBean.voucherNumber.Length; ktr1++)
Why?


Because it's easier to read (and write) .Length than .GetUpperBound(0).


Reasonable.

Thanks,

Tom
--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too

Apr 18 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.