JTextField
을 int로 변환하면 GUI 프로그램이 충돌합니다. 내가 같은 방법을 사용했기 때문에이 코드 세그먼트를 검토하고 무엇이 잘못되었는지 살펴볼 수있었습니다.JTextField에서 변환 할 때 NumberFormatException이 발생했습니다.
내가 무엇을 :
new JTextLabel l;
가 뭐죠 거기에 도착
String A = l.getText() >int i = Interger.parse(A);
코드 :
btnAdd.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int nr = Integer.parseInt(txtApt.getText());
int nrP = Integer.parseInt(txtNrPips.getText());
String owner = txtOwner.toString();
Apartment a = new Apartment(nr, nrP, owner, false);
Expense b = new Expense(Float.parseFloat(textWW.getText()), Float.parseFloat(textCW.getText()),
Float.parseFloat(textGAS.getText()), Float.parseFloat(txtELEC.getText()), Float.parseFloat(textHEAT.getText()));
ArrayList<Expense> l = new ArrayList<>();
l.add(b);
cont.addKeyWithList(a,l);
}
});
스택 :
Exception in thread "AWT-EventQueue-0" java.lang.NumberFormatException: For input string: ""
at java.lang.NumberFormatException.forInputString(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at gui.Gui$4.actionPerformed(Gui.java:195)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$200(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
수정 사항은 try/catch NumberFormatException 블록을 사용하는 것입니다. 그러나 String은 무엇에 충돌하고 있습니까? 예외 텍스트 (여기에 게시해야 함)가 알려줍니다. –
스택 오류 –
@ BogdanM을 추가했습니다. 문자열은''''입니다. 즉, 비어있어서 숫자로 파싱 할 수 없습니다. – assylias