0

I have a problem with final string. It is a mysql database client. I want to change query with clicking JButton.

public void run() {
final String query;
(...)
start.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e)
    {
if(firstSel==null || selchose.getText().equals(selchose_str) || selbase.getText().equals(base_str)) {
            query = "Select * FROM EMP";
        }
(...)

The problem is with

query = "Select * FROM EMP";

It shows me

cannot assign a value to final variable query

How to solve the problem?

Ganjira
  • 966
  • 5
  • 16
  • 32
  • I asked [a question](http://stackoverflow.com/questions/3981924/how-to-retrieve-a-value-that-must-be-computed-on-another-thread) a while back that gets at this same issue, and may be informative to you. – Matt McHenry Apr 15 '12 at 14:01

2 Answers2

2

Either make the query String a private class field or a variable local to the anonymous inner ActionListener class.

Hovercraft Full Of Eels
  • 283,665
  • 25
  • 256
  • 373
0
class YOurClassName{

private String query; //make here.....<<<<<<<<

public void run() {

(...)
start.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e)
    {
if(firstSel==null || selchose.getText().equals(selchose_str) || selbase.getText().equals(base_str)) {
            query = "Select * FROM EMP";
        }
(...)


}
Samir Mangroliya
  • 39,918
  • 16
  • 117
  • 134