Bonsoir chers amis j’ai un projet a rendre ce mercredi et je but sur une erreur. Le but du projet et décris un client et un serveur en java. Le client choisi un fichier texte et l’envoie au serveur ligne par ligne , le serveur recois les lignes et les affiches au fur et a mesure.
Pour cela dans la partie client j’ai ce code un peu restreint suivant:
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 | public Client() { setTitle("TRANSFERT DE FICHIER"); setSize(400, 500); try{ InetAddress adresse = InetAddress.getByName("127.0.0.1"); @SuppressWarnings("resource") Socket socket = new Socket(adresse, 3000); fluxSortie = new PrintStream(socket.getOutputStream()); } catch(IOException e) { System.out.println("probleme de connexion"); } void envoyerMessage(){ try{ Scanner entre = new Scanner(new FileInputStream(fichierAEnvoyer)); String ligne = entre.nextLine(); while(ligne != null){ fluxSortie.println(ligne); ligne = entre.nextLine(); } entre.close(); }catch(FileNotFoundException e){System.out.println("le fichier n'existe pas");} } ` |
Mais lorsque je clique sur le bouton envoyer qui lance la fonction envoyerMessage() on m’envoie ce message d’erreur suivant:
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 34 35 36 37 38 39 40 | Exception in thread "AWT-EventQueue-0" java.util.NoSuchElementException: No line found at java.util.Scanner.nextLine(Unknown Source) at Interface.envoyerMessage(Interface.java:79) at Interface$2.actionPerformed(Interface.java:68) 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$500(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$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source) at java.security.ProtectionDomain$JavaSecurityAccessImpl.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$JavaSecurityAccessImpl.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) |
ligne = entre.nextLine(); c’est cette instruction qui renvoie l’erreur.
Pouvez vous m’aidez? merci pour vos réponses.
+0
-0