cannot be resolved to a variable/Illegal modifier for parameter
我是eclipse初学者,请问一下提示错误:1) cannot be resolved to a variable
2) Illegal modifier for parameter dis; only final is permitted
是怎么回事呢?我都是按照教程来的。。。
package hk.android;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.*;
public class MAIN extends Activity {
private Button btnDoSug;
private EditText edtSex, edtAge;
private TextView txtResult;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
btnDoSug = (Button)findViewById(R.id.btnDoSug);
edtSex = (EditText)findViewById(R.id.edtSex);
edtAge = (EditText)findViewById(R.id.edtAge);
txtResult = (TextView)findViewById(R.id.txtResult);
btnDoSug.setOnClickListener(btnDoSugOnClick);
// System said : btnDoSugOnClick cannot be resolved to a variable
private Button.OnClickListener btnDoSugOnClick = new Button.OnClickListener() {
// Illegal modifier for parameter btnDoSugOnClick; only final is permitted
public void onClick(View v) {
String strSex = edtSex.getText().toString();
int iAge = Integer.parseInt(edtAge.getText().toString());
String strSug = "Reults=";
if (strSex.equals("M"))
if (iAge < 28)
strSug += "Not urgent";
else if (iAge > 33)
strSug += "Find Right one quickly";
else
strSug += "Enjoy your life now";
else
if (iAge < 25)
strSug += "Not urgent";
else if (iAge > 30)
strSug += "Find Right one Quickly";
else
strSug += "Enjoy your life now";
txtResult.setText(strSug);
}
};
}
} --------------------编程问答-------------------- 1.局部变量一定要先定义,再使用
2.局部变量的 定义,不需要private,public这些修饰符 --------------------编程问答-------------------- 1.btnDoSug.setOnClickListener(btnDoSugOnClick);
这句放到btnDoSugOnClick的定义后面去
2.private Button.OnClickListener btnDoSugOnClick
这句去掉 private
补充:Java , Eclipse