SHARE
TWEET

Untitled

a guest Jun 24th, 2019 47 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. run:
  2. Conectado OK
  3. Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
  4.     at proxy.SocketConnect.writeLine(SocketConnect.java:51)
  5.     at main.EnviodeDatos.actionPerformed(EnviodeDatos.java:50)
  6.     at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022)
  7.     at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2348)
  8.     at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
  9.     at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
  10.     at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
  11.     at java.awt.Component.processMouseEvent(Component.java:6539)
  12.     at javax.swing.JComponent.processMouseEvent(JComponent.java:3324)
  13.     at java.awt.Component.processEvent(Component.java:6304)
  14.     at java.awt.Container.processEvent(Container.java:2239)
  15.     at java.awt.Component.dispatchEventImpl(Component.java:4889)
  16.     at java.awt.Container.dispatchEventImpl(Container.java:2297)
  17.     at java.awt.Component.dispatchEvent(Component.java:4711)
  18.     at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4904)
  19.     at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4535)
  20.     at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4476)
  21.     at java.awt.Container.dispatchEventImpl(Container.java:2283)
  22.     at java.awt.Window.dispatchEventImpl(Window.java:2746)
  23.     at java.awt.Component.dispatchEvent(Component.java:4711)
  24.     at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:760)
  25.     at java.awt.EventQueue.access$500(EventQueue.java:97)
  26.     at java.awt.EventQueue$3.run(EventQueue.java:709)
  27.     at java.awt.EventQueue$3.run(EventQueue.java:703)
  28.     at java.security.AccessController.doPrivileged(Native Method)
  29.     at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:74)
  30.     at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:84)
  31.     at java.awt.EventQueue$4.run(EventQueue.java:733)
  32.     at java.awt.EventQueue$4.run(EventQueue.java:731)
  33.     at java.security.AccessController.doPrivileged(Native Method)
  34.     at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:74)
  35.     at java.awt.EventQueue.dispatchEvent(EventQueue.java:730)
  36.     at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:205)
  37.     at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
  38.     at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
  39.     at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
  40.     at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
  41.     at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
  42.      
  43. package main;
  44.  
  45. import java.awt.event.ActionEvent;
  46. import java.awt.event.ActionListener;
  47. import java.util.Scanner;
  48.  
  49. import javax.swing.JButton;
  50. import javax.swing.JFrame;
  51. import javax.swing.JTextField;
  52.  
  53. import proxy.SocketConnect;
  54. import proxy.SocketInter;
  55. import proxy.SocketInter;
  56. import proxy.SocketConnect;
  57.  
  58. public class EnviodeDatos extends JFrame implements ActionListener {
  59.  
  60.     JTextField textmensaje;
  61.     JButton btsend;
  62.  
  63.     /**
  64.      *
  65.      */
  66.     public EnviodeDatos() {
  67.         textmensaje = new JTextField();
  68.         textmensaje.setBounds(10, 10, 200, 120);
  69.         add(textmensaje);
  70.         btsend = new JButton();
  71.         btsend.setText("SEND");
  72.         btsend.setBounds(10, 135, 120, 20);
  73.         btsend.addActionListener((ActionListener) this);
  74.         add(btsend);
  75.         setLayout(null);
  76.         setSize(400, 400);
  77.         setVisible(true);
  78.     }
  79.  
  80.     public static void main(String[] args) {
  81.         // TODO Auto-generated method stub
  82.         new EnviodeDatos();
  83.     }
  84.  
  85.     @Override
  86.     public void actionPerformed(ActionEvent arg0) {
  87.         // TODO Auto-generated method stub
  88.         if (arg0.getSource() == btsend) {
  89.  
  90.             SocketInter socket = (SocketInter) new SocketConnect("127.0.0.1", 8080);
  91.             socket.writeLine(textmensaje.getText());
  92.  
  93.             socket.dispose();
  94.  
  95.         }
  96.     }
  97.  
  98. }
  99.      
  100. package proxy;
  101.  
  102. public interface SocketInter {
  103.     String readLine();
  104.     void  writeLine(String str);
  105.     void  dispose();
  106. }
  107.      
  108. package proxy;
  109.  
  110. import java.io.BufferedReader;
  111. import java.io.DataOutputStream;
  112. import java.io.IOException;
  113. import java.io.InputStreamReader;
  114. import java.io.PrintWriter;
  115. import java.net.ServerSocket;
  116. import java.net.Socket;
  117.  
  118. public class SocketConnect implements SocketInter {
  119.  
  120.     private Socket socket;
  121.     private BufferedReader in;
  122.     private PrintWriter out;
  123.  
  124.     /**
  125.      * @param socket
  126.      * @param in
  127.      * @param out
  128.      */
  129.     public SocketConnect(String host, int port) {
  130.         try {
  131.  
  132.             Socket socket = new Socket(host, port);
  133.             in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
  134.             out = new PrintWriter(socket.getOutputStream(), true);
  135.             System.out.println("Conectado OK ");
  136.         } catch (IOException e) {
  137.             System.out.println(e.getMessage());
  138.  
  139.         }
  140.     }
  141.  
  142.     @Override
  143.     public String readLine() {
  144.         String str = null;
  145.         try {
  146.             str = in.readLine();
  147.         } catch (IOException e) {
  148.             e.printStackTrace();
  149.         }
  150.         return str;
  151.     }
  152.  
  153.     @Override
  154.     public void writeLine(String str) {
  155.         // TODO Auto-generated method stub
  156.         // 4. The wrapper delegates to the target
  157.         try {
  158.             DataOutputStream data = new DataOutputStream(socket.getOutputStream());
  159.  
  160.             data.writeUTF(str);
  161.             System.out.println("Dato enviado");
  162.  
  163.         } catch (IOException e) {
  164.             // TODO Auto-generated catch block
  165.             System.out.println("Dato no enviado: " + e.getMessage());
  166.         }
  167.  
  168.     }
  169.  
  170.     @Override
  171.     public void dispose() {
  172.         // TODO Auto-generated method stub
  173.         try {
  174.             socket.close();
  175.  
  176.         } catch (IOException e) {
  177.             e.printStackTrace();
  178.         }
  179.     }
  180. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top