Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

ArrayList going out of scope?

843789May 18 2010 — edited May 18 2010
Hi, I have a JSP running on a portal that doesn't give me much in the way of debugging information, however I believe that I have a scope problem with the following code, where I declare and initialise an ArrayList outside a for loop, but once used in the for loop, it seems to go out of scope and cannot be referenced elsewhere in the code (object not found generic error is all I get, but this is not the raw Java error).

try
{
...
ArrayList assList = null;
ArrayList assEmailList = null;
String[] assArray = null;
...
try
{
if (actionField.equalsIgnoreCase("CREATE"))
{
if( req.containsKey( "Assignee" ) )
{
assCol = ((String[])req.get("Assignee"))[0];
assArray = assCol.split(";");
assList = new ArrayList(Arrays.asList(assArray)); //Assign values to array list here
}
if (null == assEmailCol || assEmailCol.equalsIgnoreCase(""))
{
try
{
conn= DALTool.getConnection(dmDal);

String tempAssEmail = "";
boolean chkOwnerAdded = false;
assEmailList = new ArrayList();
for(int i=0; i <= assList.size(); i++)
{
stmt = null;
stmt = conn.createStatement();
//Start of PEOPLE db call
_sql = "some sql select '" + assList.get(i).toString() + "'";
System.out.println(assList.get(i).toString()); //Here I get the values output to my log file
rs = stmt.executeQuery(_sql);
while (rs.next())
{
tempAssEmail = rs.getString(1);
}
if (null != tempAssEmail && !tempAssEmail.equalsIgnoreCase(""))
{
assEmailList.add(tempAssEmail);
}
else
{
if (chkOwnerAdded==false)
{
assEmailList.add(userName.substring(0, userName.indexOf('@')) + emailAddress);
assList.set(i, userName.substring(0, userName.indexOf('@')));
chkOwnerAdded=true; //do this only once
}
else
{
assList.remove(i); //I have checked and this is not being called
}
}
System.out.println(assList.get(0).toString()); //Here I get the value output to my log file
}
System.out.println(assList.get(0).toString()); //Here I DO NOT get the value output to my log file
}
catch (ConnectionNotAvailableException cnaEx)
{
throw new Exception("Connection problems...");
}
catch (RequiresUserNamePasswordException runpassEx)
{
throw new Exception("Connection problems...");
}
catch (SQLException sqlEx)
{
throw new Exception(sqlEx);
}
finally
{
if (null != conn)
{
try
{
if (null != rs)
{
rs.close();
}
if (null != stmt)
{
stmt.close();
}
conn.close();
}
catch (SQLException sqlEx)
{
sqlEx.printStackTrace();
}
}
}
//End of PEOPLE db call
}
catch (Exception Ex)
{
throw new Exception(Ex);
}
}
}
}
catch ( Exception ex )
{
// Catch any exceptions generated and display an error message
}

Can anyone tell me how to declare and initialise properly to avoid this issue?
Thanks,
Matt.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 15 2010
Added on May 18 2010
3 comments
458 views