convertir du JTextField.gettext() ent int
Bonjour,
J'ai un champs de text: JTextField
et je veux le convertir en int ou Integer
Voici le code
Code:
1 2 3 4
|
String s = new String();
s =(String) fenetreP.fenetreConteneur.fenetreSecondaire1.kValue.getText();
Integer nbClusters = strToInt(s); |
Voici la méthode strToInt:
Code:
1 2 3 4 5 6
| public static int strToInt(String s)
{
Integer ger = new Integer(s);
int i = ger.intValue();
return i;
} |
L'erreur est dans la ligne
Citation:
s =(String) fenetreP.fenetreConteneur.fenetreSecondaire1.kValue.getText();
Et voici le message d'erreur
Citation:
Exception in thread "AWT-EventQueue-0" java.lang.NumberFormatException: For input string: "k"
at java.lang.NumberFormatException.forInputString(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at java.lang.Integer.<init>(Unknown Source)
at IFCLUSTFRAME.strToInt(IFCLUSTFRAME.java:404)
at IFCLUSTFRAME$6.actionPerformed(IFCLUSTFRAME.java:479)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)Ce n'est pas un entier
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.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)