마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

[Kotlin] [Logcat] 화면 전환 버튼을 여러 번 누르면 앱이 강제 종료되는 오류

0 추천

메인 액티비티에서 버튼을 누르면 서브 액티비티1로 문제 없이 화면 전환이 잘 되는데,

서브 액티비티1에서 버튼을 누르면 서브 액티비티1_1로 전환되지 않고,

화면이 잠깐 하얘졌다가 메인 액티비티로 화면이 전환됩니다.

 

위 과정을 두 번 이상하면 앱이 강제 종료되는데, 왜 그러는지 알려주실 수 있을까요?

 

[Logcat(로그캣)] (첫 번째 시도)

2023-11-07 15:23:27.412 | 4247-4247 | AndroidRuntime | com.example.smf_android | E | FATAL EXCEPTION: main

Process: com.example.smf_android, PID: 4247

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.smf_android/com.example.smf_android.SubActivity1_1}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.

at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:4111)

at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4277)

at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:103)

at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)

at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)

at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2443)

at android.os.Handler.dispatchMessage(Handler.java:106)

at android.os.Looper.loopOnce(Looper.java:226)

at android.os.Looper.loop(Looper.java:313)

at android.app.ActivityThread.main(ActivityThread.java:8751)

at java.lang.reflect.Method.invoke(Native Method)

at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:571)

at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1135)

Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.

at androidx.appcompat.app.AppCompatDelegateImpl.createSubDecor(AppCompatDelegateImpl.java:926)

at androidx.appcompat.app.AppCompatDelegateImpl.ensureSubDecor(AppCompatDelegateImpl.java:889)

at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:772)

at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:197)

at com.example.smf_android.SubActivity1_1.onCreate(SubActivity1_1.kt:9)

at android.app.Activity.performCreate(Activity.java:8290)

at android.app.Activity.performCreate(Activity.java:8270)

at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1329)

at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:4085)

at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4277) 

at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:103) 

at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) 

at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) 

at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2443) 

at android.os.Handler.dispatchMessage(Handler.java:106) 

at android.os.Looper.loopOnce(Looper.java:226) 

at android.os.Looper.loop(Looper.java:313) 

at android.app.ActivityThread.main(ActivityThread.java:8751) 

at java.lang.reflect.Method.invoke(Native Method) 

at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:571) 

at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1135)

[Logcat(로그캣)] (두 번째 시도)

2023-11-07 15:36:46.083 | 8547-8547 | AndroidRuntime | com.example.smf_android | E | FATAL EXCEPTION: main

Process: com.example.smf_android, PID: 8547

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.smf_android/com.example.smf_android.SubActivity1_1}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.

at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:4111)

at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4277)

at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:103)

at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)

at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)

at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2443)

at android.os.Handler.dispatchMessage(Handler.java:106)

at android.os.Looper.loopOnce(Looper.java:226)

at android.os.Looper.loop(Looper.java:313)

at android.app.ActivityThread.main(ActivityThread.java:8751)

at java.lang.reflect.Method.invoke(Native Method)

at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:571)

at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1135)

Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.

at androidx.appcompat.app.AppCompatDelegateImpl.createSubDecor(AppCompatDelegateImpl.java:926)

at androidx.appcompat.app.AppCompatDelegateImpl.ensureSubDecor(AppCompatDelegateImpl.java:889)

at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:772)

at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:197)

at com.example.smf_android.SubActivity1_1.onCreate(SubActivity1_1.kt:9)

at android.app.Activity.performCreate(Activity.java:8290)

at android.app.Activity.performCreate(Activity.java:8270)

at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1329)

at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:4085)

at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4277) 

at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:103) 

at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) 

at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) 

at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2443) 

at android.os.Handler.dispatchMessage(Handler.java:106) 

at android.os.Looper.loopOnce(Looper.java:226) 

at android.os.Looper.loop(Looper.java:313) 

at android.app.ActivityThread.main(ActivityThread.java:8751) 

at java.lang.reflect.Method.invoke(Native Method) 

at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:571) 

at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1135)
통밀빵 (200 포인트) 님이 2023년 11월 7일 질문

1개의 답변

0 추천
 
채택된 답변

에레 메세지를 읽어보시면 theme이 잚못 되었다고 나오네요.

Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.

style/theme.xml(파일 이름이 다를 수 있음)에 theme이 Them.AppCompat 을 상속받았는지 확인하시고 SubActivity1_1 액티비티에서도 같은 theme을 사용 중인지 확인하세요. 그리고 AndroidMainfest.xml에 theme이 제대로 설정되어 있는지 체크하세요.

<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<application
        
        ...
        android:supportsRtl="true"
        android:theme="@style/AppTheme" /> <!-- 요기 --->

  ...

</manifest>


https://developer.android.com/develop/ui/views/theming/themes

spark (228,990 포인트) 님이 2023년 11월 7일 답변
통밀빵님이 2023년 11월 7일 채택됨
오! 해결됐습니다!! theme을 서로 다른 것을 상속 받아서 오류 났던 것이었네요. 감사합니다~!!
...