2013-10-03 2 views
0

저는 Java에 익숙하지 않으며 버튼을 눌렀을 때 테이블에 놓인 새 정보를 업데이트하려고합니다. 여기보고되지 않은 예외 ActionListener에서 java.io.IOException이 발생했습니다.

unreported exception java.io.IOException; must be caught or declared to be thrown 

나는에 문제가있어 코드 : 어떤 도움을

public static void updateAction(){ 

update.addActionListener(new ActionListener() { 


@Override 
public void actionPerformed(ActionEvent e) { 
BufferedWriter bfw = new BufferedWriter(new FileWriter(tmp)); 
for(int i = 0 ; i < table.getColumnCount() ; i++) 
{ 
bfw.write(table.getColumnName(i)); 
bfw.write("\t"); 
} 

for (int i = 0 ; i < table.getRowCount(); i++) 
{ 
bfw.newLine(); 
for(int j = 0 ; j < table.getColumnCount();j++) 
{ 
bfw.write((String)(table.getValueAt(i,j))); 
bfw.write("\t");; 
} 


} 
    bfw.close(); 

}});  
} 

감사합니다 당신이 내게 줄 수있는이 오류를 얻고있다.

답변

3

BufferedWriter의 방법은 IOException입니다. 당신은 당신의 방법 본문에 그것을 잡거나 그것을 버리도록 당신의 방법을 선언해야합니다.

ActionListener의 익명 구현을 사용하고 있으므로 actionPerformed의 서명을 변경할 수 없습니다. 따라서 IOExceptionactionPerformed 안에 넣어야합니다.

0

당신은

public void actionPerformed(ActionEvent e) throws IOException 
에서이

try { 
    .... 
} catch(IOException e) { 

} 

또는 발생 IOException이 같은 캐치 할 필요