대학 생활/Android

[Android] BadTokenException: Unable to add window -- token null is not for an application

opid 2015. 2. 10. 18:45

문제점

Dialog를 화면에 띄우려고할 때, 발생하는 에러.

BadTokenException: Unable to add window -- token null is not for an application

해결방안

대화상자 객체 생성시 파라미터를 확인할 것.

getApplicationContext()를 사용하지 말고, 액티비티명.this를 사용할 것

AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);