2014-02-08 148 views
-1

我想打印一個數組try和catch塊內,最後導出到.csv文件,但for循環提供了一個錯誤:打印在一個循環中嘗試

for(y=0; y<rows; y++){ //Error here 
      writer.append("" + sum[y]); // and here: that "y is not public..." 
      writer.append(','); 
} 

整個try和catch塊:

try 
    { 
     FileWriter writer = new FileWriter(sFileName); 
     writer.append("DisplayName"); 
     writer.append(','); 
     writer.append("Age"); 
     writer.append('\n'); 

     writer.append("MKYONG"); 
     writer.append(','); 
     writer.append("26"); 
      writer.append('\n'); 

      for(y=0; y<rows; y++){ 
       writer.append("" + sum[y]); 
      writer.append(','); 
      } 
      writer.append('\n'); 

     writer.append("YOUR NAME"); 
     writer.append(','); 
     writer.append("29"); 
     writer.append('\n'); 

      writer.append(""); 

     //generate whatever data you want 

     writer.flush(); 
     writer.close(); 
    } 
    catch(IOException e) 
    { 
     e.printStackTrace(); 
    } 

回答

1

你錯過了給變量y

for(int y=0; y<rows; y++){ //Error here 
--------^ 
       writer.append("" + sum[y]); // and here: that "y is not public....." 
       writer.append(','); 
    } 
的數據類型