> Hello there,
>
[quoted text clipped - 43 lines]
> is printing out the correct contents and length of the array even
> after it shows an error to say outofbounds!
A few things:
There's a slight disconnect between the code you say you're executing
and the output you're getting, so either you just typed it into this
message wrong, or you're not executing the code you think you are.
For instance, you reference a code line of this:
System.out.println("engineer array 0 is " + engineers[0]);
and an output line of this:
engineer array 0 length is 85
In the code, you don't say "length", but it's in the output. Again,
this could be a trivial error in the input of this message, or it
could be telling. Figure that out.
Second, you don't see the stack trace from that exception, so it's
hard to tell for certain where it's coming from. You could wrap all
of your code in a specific try/catch for that exception and print out
the stack trace. That might give you more information. If you add
that code, and the output doesn't change at all, then somehow that
exception is happening somewhere else entirely.
Third, if you say you've extracted this code into an isolated test
case, and it doesn't demonstrate the problem, then what are you doing
differently? Is the code that creates and populates the "engineers"
list really right before the code that prints out the values, or are
they perhaps in two different scopes (or threads?) where the
"engineers" list isn't populated yet?
homerjk wrote On 03/08/07 14:53,:
> Hello there,
>
[quoted text clipped - 43 lines]
> is printing out the correct contents and length of the array even
> after it shows an error to say outofbounds!
No, it's not. The final two lines of output must
be coming from somewhere else altogether, for two reasons:
First, when the exception is thrown (from whereever it
is thrown) the normal flow of control in your code is broken
off and execution resumes in a catch clause somewhere further
up the stack. This means your second and third println()
calls never execute at all (or if the exception is thrown
while constructing the String to be printed by the first,
that call is aborted and produces no output). Either way,
none of the output comes from the second two println()s.
Second, another and perhaps easier way to see that the
second two println()s don't produce the output is to note
that the output contains the substring "length " which the
println() calls do not generate. The output comes from
some entirely different piece of code.
Since the mysterious output comes from something you
haven't revealed, I'm at a loss to explain it.

Signature
Eric.Sosman@sun.com
homerjk - 08 Mar 2007 21:07 GMT
> No, it's not. The final two lines of output must
> be coming from somewhere else altogether, for two reasons:
[quoted text clipped - 19 lines]
> --
> Eric.Sos...@sun.com
Hi Guys,
Thanks for the replies.
Apologies for the mix up over what was being printed out, I typed that
out myself and just copied the first statement and pasted it out the
other two times and changed it to have the right output.
Its sorted now anyway. I re-wrote the whole thing from scratch and I
think the problem may have been coming from the use/re-use of the
prepared statements and resultsets. I gave each section its own
prepared statement and resultset and they problem now does not occur
at all. Still not too sure why though as before hand I was clearing
out the prepared statements each time...
Regardless, it is working now and I will be able to sleep tonight!
Thank you for you suggestions,
J.
homerjk - 08 Mar 2007 21:25 GMT
> homerjk wrote On 03/08/07 14:53,:
>
[quoted text clipped - 69 lines]
> --
> Eric.Sos...@sun.com
Guys, thanks for your replies, I wrote a long winded reply but it got
lost somewhere along the way.
Apologies for the confusion over the println's, this was a mistake, I
typed these out myself and this was not the actual program output.
The problem is now fixed, I re-wrote the program from scratch and I
suspect the problem was coming from the use/re-use of the prepared
statements and resultsets. On re-writing the code I gave each section
its own prepared statement and resultset and it fixed the problem. I'm
still not 100% sure as to why this was causing the problem as I was
clearing out the prepared statements before re-using them.
Regardless, the program is working now and I will be able to sleep
tonight.
Thank you,
J.