기존에 AlertDialog를
new AlertDialog.Builder(this); 와 같이 생성하였는데요,
문제는 이 Dialog 생성부분이 핸들러 안에 포함되어 있었습니다.
그래서 나중에 생성시에 BadTokenException이 나오길래
new AlertDialog.Builder(GetParent());
로 수정을 하였습니다.
그랬더니 이번엔 NullPointerException이 나오네요!!
무슨일일까요? ㅠ.ㅠ
아래는 소스코드입니다.
private final Handler mHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
switch(msg.what) {
case Common.FAILED_CONNECT:
AlertDialog alert = new AlertDialog.Builder(getParent()).
setTitle("Connection Failed").
setMessage("Connect to another device.\nRetry?")
.show();
break;
}
}
}
getParent 자체가 null이니까 그런거 아닌가요
this라는건 액티비티일테고 getParent라는건 this.getParent()랑 같은말이므로 액티비티의 상위 부모인데
상위부모가없으니 null떨어지는거같은데여
AlertDialog alert = new AlertDialog.Builder(getParent()).
setTitle("Connection Failed").
setMessage("Connect to another device.\nRetry?")
.show();
-------------------------------------------
위 소스에서 Builder에 create()함수 를 안넣었네요?
만약 넣고도 에러가 난거라면 getParent() 함수 말고 Activity.this 를 넣어보세요
여기서 Activity 현재의 Activity 클래스명을 적어주셔야 합니다
핸들러 안에서 선언된 것이기 때문에 this 만 적으시면 this = handler 로 인식하게 되서 오류가 납니다




이 액티비티를 구성하는 클래스는 Activity 클래스를 상속받은 Base 클래스를 상속받은 하위 클래스입니다.