473,406 Members | 2,620 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Null vs undefined

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
6 6028
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
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

"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

"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
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
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: Don Vaillancourt | last post by:
What's going on with Javascript. At the beginning there was the "undefined" value which represented an object which really didn't exist then came the null keyword. But yesterday I stumbled...
3
by: k0t1k | last post by:
Sorry if I am kicking the dead horse, but why null == undefined in Rhino? This is what I got running Rhino shell. $ java -jar js.jar Rhino 1.6 release 1 2004 11 30 js> null == undefined true...
2
by: Thomas G. Marshall | last post by:
Arthur J. O'Dwyer <ajo@nospam.andrew.cmu.edu> coughed up the following: > On Thu, 1 Jul 2004, Thomas G. Marshall wrote: >> >> Aside: I've looked repeatedly in google and for some reason cannot >>...
99
by: Mikhail Teterin | last post by:
Hello! Consider the following simple accessor function: typedef struct { int i; char name; } MY_TYPE; const char *
27
by: David W | last post by:
I'm almost tearing my hair out. A colleague claimed that a null reference can exist, like this: void f( int& p ) { printf( "%d\n", p ); } int main (int argc, char *argv) {
76
by: valentin tihomirov | last post by:
As explained in "Using pointers vs. references" http://groups.google.ee/group/borland.public.delphi.objectpascal/browse_thread/thread/683c30f161fc1e9c/ab294c7b02e8faca#ab294c7b02e8faca , the...
6
by: Java script Dude | last post by:
Small glitch (IMHO) in JavaScript is related to isNaN() boolean function. If passed a null, it returns true which is incorrect. This one cause me quite a bit of grief until I detected it and was...
6
by: jason.cipriani | last post by:
Is it OK to dereference NULL pointers if the only thing you are doing is storing them in a reference then comparing addresses to NULL again later, as in: === BEGIN EXAMPLE === Something...
2
by: Doogie | last post by:
Hi, I'm writing Javascript code to parse out a query string. I want to handle the case where a parameter value may not be sent. So consider a parameter called "State". If the user doesn't pass...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.