I have this error: Exception in thread "Thread-0" java.lang.NullPointerException

579 views Asked by At

I need to send information(ip+nombre+ventas)from a client to a server through a socket, but it doesn't work. I have to put this information in a TREE SET collection. I have a project with two java class, one is this and the other one is ObjServidor, where the functions as getventas, getip, getnombre are implemented. Could you help me?

public class HILO extends Thread {

    private final Socket s;
    private final TreeSet<ObjServidor> O;

    HILO(Socket s, TreeSet<ObjServidor> O) {

        this.s = s;
        this.O = O;

    }

    @Override
    public void run() {

        try {

            ObjectInputStream pw = new ObjectInputStream(
                    s.getInputStream());

            // RECORRER LA COLECCION EXTRAYENDO NOMBRE Y VENTAS Y CON EL SOCKET LA IP
            // CREO UNA INSTANCIA PARA CADA ELEMENTO QUE RECIBIMOS NEW
            // HACEMOS EL PUT TODO MEDIANTE UN ITERADOR
            // SACAMOS EL CONTENIDO DE LA COLECCION
            String ip, nombre;
            int ventas;

            TreeSet<ObjServidor> servidorHS = new TreeSet<ObjServidor>();


           Iterator<ObjServidor> it = O.iterator();
            while (it.hasNext()) {
                ObjServidor aux2;
                aux2 = it.next();
                nombre = aux2.getNombre();
                ventas = aux2.getVentas();
                ip = s.getRemoteSocketAddress().toString();
            }
            ObjServidor aux []=new ObjServidor[10];
            for(int i=0;i<10;i++)
            {   
              aux[i]= new ObjServidor();
            }
            for(int i=0;i<aux.length;i++)
            {
                servidorHS.add(aux[i]);

            }

            it = servidorHS.iterator();
            while (it.hasNext()) {

                System.out.println(it.next());
            }
            System.out.println("Peticiones recibidas ");
            pw.close();
            s.close();

        } catch (IOException e) {
            e.printStackTrace();
        }

    }

}
0

There are 0 answers