#1 Le 08/08/2008, à 16:41
- Kranagard
[resolu]petit probleme de parseint en java
voila j'ai ce code:
private void bokActionPerformed(java.awt.event.ActionEvent evt) {
int l = java.lang.Integer.parseInt(longueur.getText());
sachant que bok est un:
private javax.swing.JButton bok;
et longueur:
private javax.swing.JTextField longueur;
il compile sans probleme mais a l'execution il plante sur cette ligne. dans le debugger si je tape cette commande dans un watch au moment ou elle devrait etre executée j'obtiens ça:
>Exception occurred in target VM<
si je parseInt n'importe quel String il me le prend sans probleme mais la pas moyen de trouver pourquoi il en veut pas
je suis nouveau dans le java mais je programme beaucoup plus en c, c++ et c# (d'ou l'idée de me mettre au java plus qu'au c# )donc hesitez a etre precis et a parler normalement ^^
voila, si quelqu'un a une idée...
Dernière modification par Kranagard (Le 08/08/2008, à 16:57)
Hors ligne
#2 Le 08/08/2008, à 16:50
- ®om
Re : [resolu]petit probleme de parseint en java
Et dans la console il écrit quoi?
Integer.parseInt("3");
ça fait 3.
Donc si tu nous dis ce que vaut longueur.getText(), on pourra t'aider
Hors ligne
#3 Le 08/08/2008, à 16:52
- Kranagard
Re : [resolu]petit probleme de parseint en java
longueur.getText() = "2"
mais meme en recuperant dans un String ce "2" il n'en veut toujours pas lors du parseInt, meme si je passe par un Integer.valueOf()
j'obtiens toujours la meme erreur citée plus haut.
Dernière modification par Kranagard (Le 08/08/2008, à 16:53)
Hors ligne
#4 Le 08/08/2008, à 16:54
- ®om
Re : [resolu]petit probleme de parseint en java
Justement, l'erreur tu ne l'as pas citée.
Donne la stacktrace affichée dans la console !
Hors ligne
#5 Le 08/08/2008, à 16:55
- Kranagard
Re : [resolu]petit probleme de parseint en java
run-single:
Exception in thread "AWT-EventQueue-0" java.lang.NumberFormatException: For input string: " 2"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
at java.lang.Integer.parseInt(Integer.java:447)
at java.lang.Integer.parseInt(Integer.java:497)
at TestTransports.TestFerrys.bokActionPerformed(TestFerrys.java:157)
at TestTransports.TestFerrys.access$200(TestFerrys.java:5)
at TestTransports.TestFerrys$3.actionPerformed(TestFerrys.java:75)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1849)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2169)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:420)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:258)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
at java.awt.Component.processMouseEvent(Component.java:5517)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3135)
at java.awt.Component.processEvent(Component.java:5282)
at java.awt.Container.processEvent(Container.java:1966)
at java.awt.Component.dispatchEventImpl(Component.java:3984)
at java.awt.Container.dispatchEventImpl(Container.java:2024)
at java.awt.Component.dispatchEvent(Component.java:3819)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4212)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3892)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3822)
at java.awt.Container.dispatchEventImpl(Container.java:2010)
at java.awt.Window.dispatchEventImpl(Window.java:1791)
at java.awt.Component.dispatchEvent(Component.java:3819)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:463)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)
Hors ligne
#6 Le 08/08/2008, à 16:56
- ®om
Hors ligne
#7 Le 08/08/2008, à 16:57
- Kranagard
Re : [resolu]petit probleme de parseint en java
<= retourne se coucher
oki merci bien
je l'avais pas vu du coup je cherchais plus loin.
Hors ligne