[英]Java - Cannot assign a value to final variable query. It is final String
I have a problem with final string. 我的最终字符串有问题。 It is a mysql database client. 它是一个mysql数据库客户端。 I want to change query with clicking JButton. 我想通过单击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? 如何解决问题?
使查询String成为私有类字段或匿名内部ActionListener类的本地变量。
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";
}
(...)
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.