Notice
Recent Posts
Recent Comments
Link
JY Tech
[안드로이드]findViewById오류 본문
안드로이드 스튜디오에서 Java로 코딩을 하던 중
Button btn1=findViewById(R.id.button);
를 하는데 findViewById에서 오류가 났다.
찾아보니 보통 class에서는 저렇게 하는게 맞지만
fragment에서는 findViewById를 조금 다르게 접근해야 한다.
1. View매개변수 사용
Button btn1=view.findViewById(R.id.button);
이렇게 findViewById에 view.을 붙여주는 것이다.
2. getView()사용
Button btn1=getView().findViewById(R.id.button);
이렇게 findViewById에 getView().을 붙여주는 것이다.
결론: fragment에서는 findViewById를 그냥 쓰면 안된다!!
'Programming > Error Solution' 카테고리의 다른 글
[Android] unable to instantiate activity componentinfo (0) | 2024.02.21 |
---|---|
[파이썬] raise KeyError(key) from err (1) | 2023.11.27 |
[파이썬]xlrd.biffh.XLRDError(xlrd오류) (1) | 2023.11.10 |
[C#/윈폼]"도구상자 항목 '###'을(를) 로드하지 못했습니다. 해당 항목은 도구상자에서 제거됩니다. (0) | 2023.04.30 |
[파이썬,sqlite] incorrect number of bindings supplied. the current statement uses 1 and there are 3 supplied (0) | 2023.04.21 |