이 ClassCastException
를 던졌습니다 (ie.itemCode
) .Exception 모두의 Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String
.setText()가 ClassCastException을 발생시키는 이유는 무엇입니까? 나는 텍스트 필드에 (<code>ie.showItem</code>)의 JTable의 선택된 행의 값을 설정하려고 .when이 코드를 수행하는 이유
showItem = new JTable();
showItem.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
int rowCount=showItem.getRowCount();
if(rowCount>=1){
//Why it is throwing ClassCastException
itemCode.setText((String)showItem.getValueAt(showItem.getSelectedRow(), 0));
}
}
});
예외 메시지로 표시된대로 getValueAt'에서 반환 된 객체 (Integer)는 String으로 캐스팅 될 수 없기 때문에. 이것은'setText'와는 아무런 관련이 없으며 인수로 사용 된 표현식으로 인해 발생합니다. 또 다른 질문이 있었습니까? – user2864740
@Mukund show itemCode 클래스 –
.toString() 메서드 사용 – HaroldSer