Kotlin/냉장고 앱
[Android Studio] You need to use a Theme.AppCompat theme (or descendant) with this activity 에러 해결
yeeejji
2024. 3. 11. 22:12
728x90
에뮬레이터를 실행시켰는데, 다음과 같은 에러가 발생하면서 앱이 강제 종료되었다.
java.lang.RuntimeException: Unable to start activity ComponentInfo { }: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
해당 activity의 테마를 AppCompat으로 변경하라는 에러 메세지다.
⚠️
✔️ 해결 과정
1. res/values 폴더에 styles.xml을 생성한 뒤, 다음과 같이 AppCompat 테마를 정의했다.
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
</style>
</resources>
쏘 심플
당장 에러 해결이 목표이기 때문에 커스텀은 패스!
2. 에러가 발생한 activity의 테마를 @style/AppTheme로 변경했다.
<activity
android:name=".StartActivity"
android:theme="@style/AppTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
끝!! 이제 앱이 강제 종료되지 않고 잘 실행된다!
cf )
@style/AppTheme을 사용하기 위해서는 AppCompat 라이브러리에 대한 의존성이 필요하다.
build.gradle(Module:app) 파일에 다음과 같이 추가하면 된다.
implementation 'androidx.appcompat:appcompat:1.4.0'