07-15 15:19:04.680: E/AndroidRuntime(9733): java.lang.NoSuchMethodError: android.view.ViewTreeObserver.removeOnGlobalLayoutListener
There are two methods in ViewTreeObserver
with almost the same name.
removeOnGlobalLayoutListener(ViewTreeObserver.OnGlobalLayoutListener victim)
(on then global) is a method that was added in API 16. It replaces
removeGlobalOnLayoutListener(ViewTreeObserver.OnGlobalLayoutListener victim)
(global then on) which has existed since API 1, but which is now deprecated. Compatibility libraries can cause confusion about these two methods; it can appear present at compile-time but fail subsequently.
This code thwarts the error:
try {
thing.removeOnGlobalLayoutListener(victim);
} catch (NoSuchMethodError x) {
thing.removeGlobalOnLayoutListener(victim);
}
So does this code:
if(Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
thing.removeGlobalOnLayoutListener(victim);
} else {
thing.removeOnGlobalLayoutListener(victim);
}
android - Why does removeOnGlobalLayoutListener throw a NoSuchMethodError_ - Stack Overflow.pdf
'JAVA > Android' 카테고리의 다른 글
[안드로이드] 메뉴 추가 (0) | 2014.07.21 |
---|---|
[안드로이드] API 버전 체크 (0) | 2014.07.15 |
[Android] 텍스트뷰 폰트 사이즈 조절. (0) | 2014.07.10 |
[안드로이드] 같은 균등 Width 분할 (0) | 2014.07.02 |
[안드로이드] fragment 에서 findViewById (0) | 2014.07.02 |