Android
[Android] java.lang.ClassCastException
th.k
2025. 6. 12. 14:51
androidx.constraintlayout.widget.ConstraintLayout$LayoutParams cannot be cast to android.widget.LinearLayout$LayoutParams
이것은 단순히 `View`에 `LayoutParams`을 `set`할 때 부모 레이아웃 타입의 `LayoutParams`를 사용하지 않아서 발생하는 Exception이다.
그런데 디버깅을 하면서 알아낸 것이 있어서 기록해놓는다.
- visibility가 `GONE`인 `View`는 해당 Exception이 발생하지 않는다.
실제로 화면에 그려질 때 발생하는듯 싶다. - `try-catch`로 잡히지 않는다.
실제로 화면에 그려질 때 발생하는 것으로 짐작했을 때, `setLayoutParams` 메서드를 호출하는 순간에 발생하지 않아서 `try-catch`로 잡히지 않는다.