버터나이프 & 데이터바인딩 (kotlin-kapt) 사용하며 발생하는 NPE
Search
♠️

버터나이프 & 데이터바인딩 (kotlin-kapt) 사용하며 발생하는 NPE

생성일
2021/09/06 01:16
태그
Runtime: FATAL EXCEPTION: main Process: com.singvana.app, PID: 28732 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.singvana.app/com.singvana.app.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setVisibility(int)' on a null object reference at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3121) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3264) at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78) at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1955) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loop(Looper.java:214) at android.app.ActivityThread.main(ActivityThread.java:7078) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:964) Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setVisibility(int)' on a null object reference at com.singvana.app.MainActivity.init(MainActivity.java:326) at com.singvana.app.MainActivity.onCreate(MainActivity.java:154) at android.app.Activity.performCreate(Activity.java:7327) at android.app.Activity.performCreate(Activity.java:7318) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1275) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3101) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3264) at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78) at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1955) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loop(Looper.java:214) at android.app.ActivityThread.main(ActivityThread.java:7078) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:964) I/Process: Sending signal. PID: 28732 SIG: 9
Kotlin
바인딩어댑터를 사용하려고 apply plugin: 'kotlin-kapt' 를 추가하면
엉뚱한 곳에서 위와 같은 에러가 발생한다. 주로 버터나이프 사용한 곳에서 에러가 발생하는데,
kapt 'com.github.bumptech.glide:compiler:4.11.0' kapt "com.jakewharton:butterknife-compiler:10.2.3" implementation "com.jakewharton:butterknife:10.2.3"
Kotlin
위와 같이 추가해주고 해결했다.