i am making an app that passes some command to a socket. the app has a list 
of the sockets i can pass commands to. it also has the option to set 
schedule on when to pass a command to socket/s. passing command from the 
adapter is ok, but passing from the activity from the schedule throws npe. 
i wonder why this happens even though those codes are the same.

here's those codes;

public void willSend (final int type, final String ip, final String port, final 
int pin_id, final int status) {
    new Thread(new Runnable() {
        @Override
        public void run() {
            try {
                InetAddress serverAddr = InetAddress.getByName(ip);
                socket = null;
                if(socket == null) {
                    socket = new Socket(serverAddr, Integer.parseInt(port));
                }
            } catch (Exception ex) {

            }
            if (type == 1) {
                sendOpen(socket, pin_id, status);
            }else {
                sendClose(socket, pin_id, status);
            }
        }
    }).start();
}

public void sendOpen (Socket socket, int pinid, int status) {
    OutputStream output;
    try {
        abc[2] = (byte)pin_number;
        abc[3] = OPEN;
        if (socket.isConnected()) {
            output = socket.getOutputStream();
            output.write(abc);
            output.flush();
            //output.close();

        }
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }finally{

    }
}

public void sendClose (Socket socket, int pinid, int status) {
    OutputStream output;
    try {
        abc[2] = (byte)pin_number;
        abc[3] = CLOSE;
        if (socket.isConnected()) {
            output = socket.getOutputStream();
            output.write(abc);
            output.flush();
            //output.close();

        }
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}


please help me. i don't know how to fix this anymore.

-- 
You received this message because you are subscribed to the Google Groups 
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to android-developers+unsubscr...@googlegroups.com.
To post to this group, send email to android-developers@googlegroups.com.
Visit this group at https://groups.google.com/group/android-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/android-developers/d11ed55b-fb72-4739-9a6b-40f7352af1f4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to