[Android] Unable to start activity ComponentInfo 에러

Happy Jiwon·2023년 4월 2일
1

Error

목록 보기
2/2

문제


위 에러의 Unable to start activity ComponentInfo 는 말 그대로 액티비티가 시작될 때 화면을 로드하지 못할 경우 발생하는 에러이다.

[검색 결과]

  • Android Studio가 API나 라이브러리를 찾지 못하는 경우
  • xml 파일에서의 화면 설정에 오류가 있을 경우(LinearLayout 사용시 orientation 미설정)
  • Intent로 데이터를 받아오면서 넘겨줄 때 intent.putExtra(); 를 해주지 않을 경우

등등... 여러 이유가 있다.

에러 발생 위치

public class MainActivity extends AppCompatActivity {
@BindView(R.id.rv_repos)
RecyclerView recyclerView;
...
	@Override
    protected void onCreate(Bundle savedInstanceState) {
    ButterKnife.bind(this);
    
    ...
    
	recyclerView.setLayoutManager(new LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false));
	...
    
    }
 }

앱 실행을 하면 Unable to start activity ComponentInfo 에러와 함께 recyclerView 에서 NPE가 발생했다고 알려준다.
그래서 리사이클러뷰쪽만 겁나 보고있었다..

원인

build.gradle에서 kotlin-kapt 플러그인을 추가한 적이 있었는데.. (문제의 이유)
Kotlin을 사용하는 경우에는 annotationProcessorkapt로 바꿔줘야한다.
ButterKnife

수정 전 build.gradle

dependencies {
...
implementation 'com.jakewharton:butterknife:10.2.3'
annotationProcessor 'com.jakewharton:butterknife-compiler:10.2.3'
}

수정 후 build.gradle

dependencies {
...
implementation 'com.jakewharton:butterknife:10.2.3'
kapt 'com.jakewharton:butterknife-compiler:10.2.3'
}
profile
공부가 조은 안드로이드 개발자

0개의 댓글