The final local variable cannot be assigned, since it is defined in an enclosing type

来源:互联网 发布:fgo淘宝石头号注意事项 编辑:程序博客网 时间:2024/06/10 04:27

Android项目中遇到的问题,想弹出一个自定义dialog,dialog里有一个下拉列表spinner,当点击完item时,返回被选择的item。代码如下,

     //添加事件Spinner事件监听                spinner.setOnItemSelectedListener(new OnItemSelectedListener() {                 public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,                           long arg3) {                       keyFile=list.get(arg2);                 }                   public void onNothingSelected(AdapterView<?> arg0) {                   }              }); 

此时会报错The final local variable keyFile cannot be assigned, since it is defined in an enclosing type

解决办法:将本地变量改为局部或全局变量,即将本地变量keyFile定义在函数体外,即可解决。

感谢这里,英文好的话,原版解释在这。等有时间做详细翻译。

0 0