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哪位大侠指教!!!

解决方案 »

  1.   

    index1, index2 哪来的?list3 哪来的?啥都没有!
      

  2.   

    inner class needs to be defined as a final class...
      

  3.   

     public demo() 
      { 
          ... 
          for(int j=0;j <str[index1][index2].length;j++) 
      list3.addItem(str[index1][index2][j],j);  
      } 
    in ...?  hehe
      

  4.   

    这三个参数不用管,index1,index2是int 型的变量,list3是List组件
      

  5.   

    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;
      

  6.   

    But when i changed the code as :"private final String str = ...."
    The compiled result is the same..
      

  7.   

    final private String str = "";
    Try!
      

  8.   

    LZ的源代码里面应该不象贴出来的这样子吧?
    从异常里面看,str应该是一个内部类里面的。要把它设为final的。
      

  9.   

    local variable str is accessed from within inner class; needs to be declared final 
    其实就是这个错,把你的代码粘出来看看,大致意思就是内部类访问不了局部变量,需要定义成final的。