Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

local variable accessed from within inner class

Status
Not open for further replies.

gwu

MIS
Dec 18, 2002
239
US
Can some one please help with this error?

Thanks in advance.

JFrame_1.java [108:1] local variable strings is accessed from within inner class; needs to be declared final
public int getSize() { return strings.length; }
***********
with this code:

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
String[] strings = new String[5];
int myNumber = 0;
String dbURL = "jdbc:eek:dbc:myDB";
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}catch (ClassNotFoundException e) {
System.out.println("Database access failed " + e);
}
try {
Connection conn = DriverManager.getConnection(dbURL,"*****","*****");
Statement stmt=conn.createStatement();
ResultSet rs=stmt.executeQuery("select firstName from GetConReg where lastName != ''");
while(rs.next()){
strings[myNumber] = rs.getString(1);
myNumber++;
}

}catch (SQLException e) {
System.out.println("Database access failed " + e);
}

jList1.setModel(new javax.swing.AbstractListModel() {
public int getSize() { return strings.length; }
public Object getElementAt(int i) { return strings; }
});
}
***********
 
Change

String[] strings = new String[5];
to
final String[] strings = new String[5];
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top