以下代码获取错误“无法引用在不同方法中定义的内部类中的非最终变量myid”,为什么?谢谢!
private void DeleteSingleSMS(long myid){
AlertDialog.Builder builder = new Builder(this);
builder.setMessage(getString(R.string.DeleteContent));
builder.setTitle(getString(R.string.DeleteTitle));
builder.setPositiveButton(getString(R.string.DeleteOK), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
String uri = "content://sms/" +myid;
getContentResolver().delete(Uri.parse(uri), null, null);
}
});
builder.setNegativeButton(getString(R.string.DeleteCancel),
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
}
});
builder.create().show();
}
答案 0 :(得分:2)
因为myid
未被声明为final。变化
DeleteSingleSMS(long myid)
到
DeleteSingleSMS(final long myid)