当前位置: 代码迷 >> J2SE >> 请问 : 三维数组有关问题
  详细解决方案

请问 : 三维数组有关问题

热度:59   发布时间:2016-04-24 12:52:52.0
请教 : 三维数组问题

public demo extends Frame
{
  private String str[][][] =
  {
  { {"",""},{"",""},{"",""}... },
  { {"",""},{"",""},{"",""}... },
  ...
  };
  public demo()
  {
  ...
  for(int j=0;j<str[index1][index2].length;j++)
list3.addItem(str[index1][index2][j],j);  
  }
}
编译报错:
  ---------- javac ----------
Demo.java:222: local variable str is accessed from within inner class; needs to be declared final
for(int j=0;j<str[index1][index2].length;j++)
Demo.java:222: array required, but java.lang.String found
for(int j=0;j<str[index1][index2].length;j++)

Demo.java:223: local variable str is accessed from within inner class; needs to be declared final 
  list3.addItem(str[index1][index2][j],j);
Demo.java:223: array required, but java.lang.String found
list3.addItem(str[index1][index2][j],j);

4 errors

哪位大侠指教!!!

------解决方案--------------------
As you know the inner class exists for its own purpose, it needs a "final" modifier. Just like you want to initialize a variable once and want it immutable, you can use "final":

Java code
final static int SIZE = 10;
------解决方案--------------------
local variable str is accessed from within inner class; needs to be declared final 
其实就是这个错,把你的代码粘出来看看,大致意思就是内部类访问不了局部变量,需要定义成final的。
------解决方案--------------------
探讨
local variable str is accessed from within inner class; needs to be declared final
其实就是这个错,把你的代码粘出来看看,大致意思就是内部类访问不了局部变量,需要定义成final的。
  相关解决方案