¿Cómo pasar un jFrame con jTable a través de sockets?

Tengo una aplicación cliente-servidor, en el lado del cliente tengo un botón para recibir un marco con una tabla dentro del servidor. Si paso el marco con otros jComponents (JButton, JTextField) funciona bien, pero cuando intento pasar el marco con un jTable obtengo una excepción nula en el lado del cliente.

Aquí está mi código:

Lado del cliente:

private class GetServerData extends Thread
{
    String server_msg = " ";
    Socket the_client;
    ObjectInputStream from_server;

    public GetServerData(Socket client)
    {
        the_client = client;
        try {
            from_server = new ObjectInputStream(the_client.getInputStream());
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public void run() 
    {
        do {
            try {
                Object obj = from_server.readObject(); // this is the line when the exception reference to 
                                                       // when trying to read the JFRAME 
                if (obj instanceof JFrame) {
                    JFrame window = (JFrame)obj;
                    window.setVisible(true);
                    window.pack();
                }
                else {
                    server_msg = (String)obj;
                    System.out.println(server_msg);
                }
            }
            catch (ClassNotFoundException | IOException e) {
                e.printStackTrace();
            }
        }while(!server_msg.equals("bye"));
    }
}

Lado del servidor:

public void run(){
    while (true){
        try {
            data_from_client = (Vector)from_client.readObject();
            if (data_from_client.elementAt(0)equals("string")) {
                String s = "Hello user";
                to_client.writeObject(s);
                to_client.flush();
            }                   
            else if (data_from_client.elementAt(0).equals("table")) {
                String [][]d = {{"yoyo","jojo"},{"koko","momo"}}; 
                String []h   = {"name","best friend"};
                JTable jtable = new JTable(d,h);
                JScrollPane scroll = new JScrollPane(jtable);
                JPanel panel = new JPanel();
                panel.add(scroll,BorderLayout.CENTER);
                JFrame frame = new JFrame("Im from the server!!");
                frame.add(panel);
                to_client.writeObject(frame);
                to_client.flush();
            }
            //else if (data_from_client.elementAt(0).equals("bye")) {
            //    to_client.println("bye");
            //    to_client.flush();
            //    socket.close();
            //    socket = null;
            //}
        }
        catch(IOException | ClassNotFoundException ioe) {
            break;
            // error in reading streams from client
        }
    }
    close();
}

La excepción es:

Exception in thread "Thread-21" java.lang.NullPointerException
at java.awt.Container.readObject(Unknown Source)
at sun.reflect.GeneratedMethodAccessor6.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at java.io.ObjectStreamClass.invokeReadObject(Unknown Source)
at java.io.ObjectInputStream.readSerialData(Unknown Source)
at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.readArray(Unknown Source)
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.access$300(Unknown Source)
at java.io.ObjectInputStream$GetFieldImpl.readFields(Unknown Source)
at java.io.ObjectInputStream.readFields(Unknown Source)
at java.awt.Container.readObject(Unknown Source)
at sun.reflect.GeneratedMethodAccessor6.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at java.io.ObjectStreamClass.invokeReadObject(Unknown Source)
at java.io.ObjectInputStream.readSerialData(Unknown Source)
at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.readArray(Unknown Source)
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.access$300(Unknown Source)
at java.io.ObjectInputStream$GetFieldImpl.readFields(Unknown Source)
at java.io.ObjectInputStream.readFields(Unknown Source)
at java.awt.Container.readObject(Unknown Source)
at sun.reflect.GeneratedMethodAccessor6.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at java.io.ObjectStreamClass.invokeReadObject(Unknown Source)
at java.io.ObjectInputStream.readSerialData(Unknown Source)
at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.readArray(Unknown Source)
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.access$300(Unknown Source)
at java.io.ObjectInputStream$GetFieldImpl.readFields(Unknown Source)
at java.io.ObjectInputStream.readFields(Unknown Source)
at java.awt.Container.readObject(Unknown Source)
at sun.reflect.GeneratedMethodAccessor6.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at java.io.ObjectStreamClass.invokeReadObject(Unknown Source)
at java.io.ObjectInputStream.readSerialData(Unknown Source)
at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.readArray(Unknown Source)
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.access$300(Unknown Source)
at java.io.ObjectInputStream$GetFieldImpl.readFields(Unknown Source)
at java.io.ObjectInputStream.readFields(Unknown Source)
at java.awt.Container.readObject(Unknown Source)
at sun.reflect.GeneratedMethodAccessor6.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at java.io.ObjectStreamClass.invokeReadObject(Unknown Source)
at java.io.ObjectInputStream.readSerialData(Unknown Source)
at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.readArray(Unknown Source)
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.access$300(Unknown Source)
at java.io.ObjectInputStream$GetFieldImpl.readFields(Unknown Source)
at java.io.ObjectInputStream.readFields(Unknown Source)
at java.awt.Container.readObject(Unknown Source)
at sun.reflect.GeneratedMethodAccessor6.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at java.io.ObjectStreamClass.invokeReadObject(Unknown Source)
at java.io.ObjectInputStream.readSerialData(Unknown Source)
at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.readArray(Unknown Source)
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.access$300(Unknown Source)
at java.io.ObjectInputStream$GetFieldImpl.readFields(Unknown Source)
at java.io.ObjectInputStream.readFields(Unknown Source)
at java.awt.Container.readObject(Unknown Source)
at sun.reflect.GeneratedMethodAccessor6.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at java.io.ObjectStreamClass.invokeReadObject(Unknown Source)
at java.io.ObjectInputStream.readSerialData(Unknown Source)
at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.readObject(Unknown Source)
at pack.connect_to_server.ServerConnection$GetServerData.run(ServerConnection.java:92)

He comentado en el lado del cliente, donde se produce la excepción.

Respuesta 1

¿Tiene ARCore un sistema de partículas (sin usar Unity)? Ya estoy usando ViroCoreAR pero ahora, quiero usar ARCore pero no sé si ARCore tiene un sistema de partículas como ViroCoreAR o incluso ARKit para (...

Estoy enfrentando un problema extraño solo en Chrome. Recibo una imagen del servidor que funciona bien en Firefox, pero en Chrome la imagen se carga por una vez y luego se muestra como una imagen rota. En consola de ...

He escaneado la mayor cantidad de información posible sobre esto y he encontrado este AVISO: Se requieren los servicios de Google Play para compilar y ejecutar este ejemplo. Se lanzará pronto. Por favor, consulte https: // ...

Me gustaría usar Java para trabajar con una estructura de datos que terminará en más de 100 GB. Necesito escribir y leer de la cosa en una proporción de 1: 1, tantas veces por segundo como sea posible. En forma de Java es un ...