Note that there are some explanatory texts on larger screens.

plurals
  1. POunable to refer to a non-final variable inside an inner class defined in an action listener
    primarykey
    data
    text
    <p>I am getting an error that says "<strong>cannot refer to a non-final variable inside an inner class defined in a different method</strong>"</p> <p>This is happening when I am trying to set up my timer referencing an action listener that I have constructed! This constructor simply displays a label and the timers desired effect is to run the action listener for 10 seconds but I can't get past this error. The code below shows he action listener and where he issue is occurring. I have put stars around the problematic areas. Thanks</p> <pre><code>**ActionListener actListner = new ActionListener() { public void actionPerformed(ActionEvent event) { lblgreenImage.setBounds(150,410,50,40); repaint(); } };** btnEnter.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { String username = txtUserName.getText(); String accessCode = txtPin.getText(); String dataSourceName = "securitysystem"; String dbUrl = "jdbc:odbc:" + dataSourceName; try{ //Type of connection driver used Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); //Connection variable or object param: dbPath, userName, password Connection con = DriverManager.getConnection(dbUrl, "", ""); Statement statement = con.createStatement(); ResultSet rs = statement.executeQuery("select username, pin from securitysystem.employee where username = '" + username + "' and pin = '" + accessCode + "'"); boolean nomatches=true; while(rs.next()) { String checkrs = rs.getString("username"); String checkPin = rs.getString("Pin"); if (username.equals(checkrs)) { if (accessCode.equals(checkPin)) { **Timer timer = new Timer(500, actListner);** **timer.start();** </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload