请教 : 三维数组问题
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":
final static int SIZE = 10;
[解决办法]
local variable str is accessed from within inner class; needs to be declared final
其实就是这个错,把你的代码粘出来看看,大致意思就是内部类访问不了局部变量,需要定义成final的。
[解决办法]