Bonjour,
J'ai un petit problème. J'utilise la classe StringTokenizer dans le but de récupérer tous les mots d'une zone de texte.
J'arrive bien à afficher les mots sur la console mais le problème intervient quand je veux stocker ces mots dans un tableau.
Etant débutante en Java, je ne comprends pas les erreurs qu' Eclipse me donne (mis à par l'indication de la ligne).
Voici mon code:
et mon erreur après avoir entré "texte à récupérer dans tableau" dans ma zone de texte
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 bouton1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e){ StringTokenizer st = new StringTokenizer(zone2.getText()); //Déclaration d'un tableau d'une colonne et 20 lignes //final String[][]tableau= new String [20][1]; int i=0; String [] tab = new String[10]; while (st.hasMoreTokens()) { System.out.println(st.nextToken()); tab[i]=st.nextToken(); i++; } } });
Ce serait vraiment gentil de m'aider.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33 texte récupérer tableau Exception in thread "AWT-EventQueue-0" java.util.NoSuchElementException at java.util.StringTokenizer.nextToken(Unknown Source) at ChatCorrect$7.actionPerformed(ChatCorrect.java:256) 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.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)
Merci
Partager