TIL #85

loci·2024년 7월 25일
0

TIL

목록 보기
81/103

다른화면으로 이동시 gif를 실행시킬때 앱꺼짐

java.lang.NullPointerException: You cannot start a load on a not yet attached View or a Fragment where getActivity() returns null (which usually occurs when getActivity() is called before the Fragment is attached or after the Fragment is destroyed).

gif를 실행시킬때 다른 화면으로 넘어간 상태일때 생기는 오류로 fragment의 lifecycle과 관련되어있다.
즉 git를 실행시킬 뷰가 없어서 생긴 오류이다.

if(activity != null)을 추가해 getActivity()가 null일때 실행되지 않도록 해주었다.

if(activity != null){  
    binding.ivFirstGif.visibility = View.INVISIBLE  
    loadGif(R.raw.gacha2, binding.ivSecondGif)  
}

fragment는 항상 activity에 부착되어 있어야하기 때문에 getActivity()로 현재 연결되어 있는 activity를 반환한다. 현재 activity가 연결되어 있지 않거나 onDetach이후에 null을 반환한다.


fragment에서 LinearLayoutManager에 context전달법

binding.rvRecentList.layoutManager = LinearLayoutManager(this.context)

폴더명 바꿨을때 빨간줄

패키지명 잘 바뀌었는지 확인해야한다. (빨간줄이 안뜸)

package com.example.sweetcontactget.fragments.randomCall

profile
편리한 개발자

0개의 댓글