Android

Caused by: java.lang.NullPointerException: Attempt to invoke virtual method ‘void androidx.appcompat.widget.ad.a()’ on a null object reference

androidx로 마이그레이션 후 발생한 오류이다.

8409/com.Test E/UncaughtException: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.Test/com.Test.MainActivity}: android.view.InflateException: Binary XML file line #37: Binary XML file line #37: Error inflating class androidx.appcompat.widget.Toolbar
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2950)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3085)
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:1816)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6853)
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:860)
Caused by: android.view.InflateException: Binary XML file line #37: Binary XML file line #37: Error inflating class androidx.appcompat.widget.Toolbar
Caused by: android.view.InflateException: Binary XML file line #37: Error inflating class androidx.appcompat.widget.Toolbar
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:343)
at android.view.LayoutInflater.createView(LayoutInflater.java:647)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:790)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:863)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:866)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
at androidx.appcompat.app.r.s(Unknown Source:159)
at androidx.appcompat.app.r.r(Unknown Source:4)
at androidx.appcompat.app.r.b(Unknown Source:0)
at androidx.appcompat.app.o.setContentView(Unknown Source:4)
at com.Test.MainActivity.onCreate(Unknown Source:6)
at android.app.Activity.performCreate(Activity.java:7151)
at android.app.Activity.performCreate(Activity.java:7142)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1272)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2930)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3085)
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:1816)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6853)
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:860)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method ‘void androidx.appcompat.widget.ad.a()’ on a null object reference
at androidx.appcompat.widget.ap.setBackgroundDrawable(Unknown Source:5)
at android.view.View.setBackground(View.java:21538)
at android.view.View.(View.java:5511)

소스코드 난독화 때문에 발생하는 오류로
proguard-rules.pro 파일에 아래 한줄을 추가하면 해결된다.
-keep class androidx.appcompat.widget.** { *; }

Leave a Reply

error: Content is protected !!