Exception when calling a Thread from another class

-1

I have a THREAD created in my MainActivity (called Menu_Main) and I want to pass it to my class (Cls_Logeo) where I log in to connect through a Switch, but clicking on the switch generates an error, I followed my Time_Stop and it shows me null, so I'm not being called to my main class thread.

It's in my class that I want to pass that thread

And this is the error that generates me, in the follow-up to the TIM I boot null: I / System.out: < < < < < < < < < < < < < < < > > > > > > > > > > > > null

    
asked by Bloom 26.07.2018 в 16:09
source

2 answers

0

You must keep your Time_Stop class in your Menu_activity class example:

static Time_stop tim= new Time_Stop()

and have it called in your Cls_logeo class this way:

Menu_Main.tim.conectar()

Or instantiate your Time_Stop class in the Csl_Login activity: in this way you can have the methods of that class called. since the exception is telling you that the object tim is null.

    
answered by 26.07.2018 / 19:53
source
0

My code is as follows in the Main Activity (Menu_Main): its thread structure:

1.- Variables:

// <editor-fold defaultstate="collapsed" desc="Variables">
        int Nro=-1,Puerto=0,NumSer=0;
        Socket Client;
        ObjectOutputStream Enviar;
        ObjectInputStream Recibir;
        Clas_ArrayList Cls_Get_Obj;
        Clas_ArrayList Cls_Ret_Tip;
        boolean Ini_Hilo=true,Corriendo=false,DatEnv=false;
        String Server="";
        int Num_Conect=0;//num con quien se conecta
        int Num_Env=-1; //num proceso pedido
        // </editor-fold>

2.-Connect

// <editor-fold defaultstate="collapsed" desc="Conectar">
        public void Conectar(String Serv,int Puert){
            Server=Serv;
            Puerto=Puert;
        }
        // </editor-fold>

3.- Time_Stop_Ini (initialize the socket):

// <editor-fold defaultstate="collapsed" desc="Time_Stop_Init">
        public void Time_Stop_Init(int Nro){
            this.Nro=Nro;
            Corriendo=true;
            Num_Env++;
        }
        // </editor-fold>

4.- Run (important (I only put the important thing because it is very very big indeed)):

public void run(){
            do {
                if(Corriendo){
                    // <editor-fold defaultstate="collapsed" desc="Switch">
                    System.out.println ("siiiiiiiiiiiiiiiiiiiiiiiiiiiiiii "+Cls_Met.CargarHoraReal ());
                    switch(Nro){
                        // <editor-fold defaultstate="collapsed" desc="0 Conexion">
                        case(0):
                            System.out.println ("Acceso S:"+Server+" : P:"+Puerto);
                            try {
                                Client = new Socket ( InetAddress.getByName ( Server ), Puerto);
                                Enviar = new ObjectOutputStream ( Client.getOutputStream () );
                                Enviar.flush ();
                                Recibir = new ObjectInputStream ( Client.getInputStream () );
                                Nro = 1;
                            } catch (IOException e) {
                                Nro = 3;
                                Log.e ( "Socket Iniciando !!!", "SI: 1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B " + Cls_Met.CargarHoraReal () );
                                e.printStackTrace ();
                            } catch (Exception e) {
                                Nro = 3;
                                Log.e ( "Socket Iniciando !!!", "SI: 2C2C2C2C2C2C2C2C2C2C2C2C2C2C2C2C2C2C2C " + Cls_Met.CargarHoraReal () );
                                e.printStackTrace ();
                            }
                            break;
}
                    }else{
                        System.out.println ("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb "+Cls_Met.CargarHoraReal ());
                    }
                    // </editor-fold>
                    // <editor-fold defaultstate="collapsed" desc="Temporalizador">
                    try {
                        sleep ( 3000 );
                    } catch (InterruptedException e) {
                        Log.e("TCP SI client", "SI: InterruptedException No corriennnnndoooooo "+Cls_Met.CargarHoraReal ());
                        e.printStackTrace ();
                    }

                    // </editor-fold>
            }while (Ini_Hilo);
        }
        // </editor-fold>
    
answered by 26.07.2018 в 18:44