And the reason why this solves the problem is . . .?

I don't mean to sound harsh, but when you answer a beginning-level question
without explaining it, you're not really helping the person to learn. The
reason may be obvious to you, but if it were as obvious to the asker, they
wouldn't have had to ask in the first place.

So, the reason that you get the "variable may not have been initialized"
message is that if an exception happens in the try block before the code
that populates the array, control is transferred to the catch block and then
if there is any access to the array after that, it won't have been
initialized. The compiler checks to see if there is any possible path of
execution that can get to a usage of a variable without going through an
assignment to that variable. If even one exists, it will give the error
message (which is why it uses the word "may", meaning "possibly").
Initializing the variable on the declaration, even to null, assures that
there is no path that leaves it uninitialized.

--Jim Preston

-----Original Message-----
From: A mailing list about Java Server Pages specification and reference
[mailto:[EMAIL PROTECTED]]On Behalf Of Yasir Feroze Minhas
Sent: Tuesday, July 18, 2000 11:05 PM
To: [EMAIL PROTECTED]
Subject: Re: accessing array initialized in a try statement


Very well, put an initialize statement before try-catch block.

For example
Vector v = null;
try
{
    populate v here
}
catch()
{}

Now you can access your Vector v without the initialization error.

regards
Y
----- Original Message -----
From: Nimmons, Daniel <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Wednesday, July 19, 2000 2:39 AM
Subject: accessing array initialized in a try statement


> being fairly new to java I am still trying to work out variable scopes. I
> have a try statement where an array is populated with values. However when
I
> try to access the values in this array from anywhere but in the try
> statement I get an "variable fileArray may not have been initialized"
how
> do I access the values in this array...
>
> Daniel (Buster) Nimmons
>
> Information Management Specialist
> Phone: (713) 845-4991
> CELL #:(281) 224-8013
> Fax #:  (713) 640-8717
> E-mail: [EMAIL PROTECTED]
>
>

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets

Reply via email to