Matthew Brown wrote:If you declare a variable in a method, you can't access it outside that method, right? That's what I mean by scope - you can only refer to a variable if it's in scope. Well, it's the same with any block (delimited by {...}). The variables you declare on line 9/10 are only in scope in the lines 9-16. Once you're outside that block, they're gone.
So the answer is, declare the variables outside the block. Move your declarations (but not the creation of the objects) outside the try block:
One more thing you now have to look out for, though: in the case of a failure to create those objects, the variables will still be null. So you need to cope with that possibility when you try to close them.
thanks a lot