아 이미지 왜 자꾸 깨짐.

이미지 자꾸 깨지니까 그냥 말로하겠음 ...딱히 할말이없네요 이미지올리고싶은데
ps&cube
접속 : 6148   Lv. 86

Category

Profile

Counter

  • 오늘 : 45 명
  • 전체 : 440382 명
  • Mypi Ver. 0.3.1 β
[학생] 안드로이드 핸들러가 잘 작동하지 않습니다. (0) 2016/01/09 PM 05:24
그냥 표준자바처럼 하면 안드로이드에서 보내는 정보가 잘 컴퓨터 서버로 도착이되는데
컴퓨터에서 받아서 처리한걸 보내면 동작이 안되더군요..핸들러의 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();
}
}
}


}

신고

 
X