0

下面的代码得到错误“Cannot reference an non-final variable myid inside an internal class defined in a different method”,为什么?谢谢!

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();        
}
4

1 回答 1

2

因为myid没有被宣布为最终的。改变

DeleteSingleSMS(long myid)

DeleteSingleSMS(final long myid)
于 2013-06-30T09:00:15.323 回答