컴퓨터에서 받아서 처리한걸 보내면 동작이 안되더군요..핸들러의 post를 써야한다고해서
아름아름 배워서 써봤는데...에러가납니다. ㅜㅠ
메인엑티비ㅇ티 클리스는 다음과같습니다.
public class MainActivity extends AppCompatActivity {
public Handler handler;
ObjectRunnable runnable;
private static final String TAG = "mainactivity";
그리고 버튼을 누르면 ConnectThread를 스타트시켜줍니다.
button.setoncl-ckListener(new View.oncl-ckListener() {
@Override
public void oncl-ck(View v) {
ConnectThread thread=new ConnectThread();
thread.start();
}
});
ConnectThread까지는 잘들어옵니다. 분명. 그런데 핸들러.post하면 runnable로 정의한
ObjectRunnable로 가야하는거같은데 가질 못하고
handler.post부분에서 다음과같이에러가납니다.
Process: com.example.user.gesture, PID: 6306 java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.os.Handler.post(java.lang.Runnable)' on a null object reference at com.example.user.gesture.MainActivity$ConnectThread.run(MainActivity.java:186)
Class ConnectThread extends Thread{
@Override
public void run() {
super.run();
Log.d(TAG, "쓰레드 들어옴 post부름");
handler.post(runnable);
Log.d(TAG, "쓰레드 들어옴 post부름1");
}
}
이런식으로 ObjectOutput, -nput을 쓰는게 맞는지요...?
public class ObjectRunnable implement Runnable{
@Override
public void run() {
String hostname="203.233.194.246";
try {
Log.d(TAG, "핸들러들어옴");
Socket client = new Socket(hostname, 8789);
oos = new ObjectOutputStream(client.getOutputStream());
ois = new Object-nputStream(client.get-nputStream());
}catch(Exception e){
e.printStackTrace();
}
}
}
}