应用程序失败:膨胀类com.github.glomadrian.materialanimatedswitch.MaterialAnimatedSwitch的错误

时间:2019-07-14 10:10:40

标签: java android

应用程序失败-原因:android.view.InflateException:二进制XML文件行#23膨胀类com.github.glomadrian.materialanimatedswitch.MaterialAnimatedSwitch

时出错

尝试更改矢量和非矢量图像

<com.github.glomadrian.materialanimatedswitch.MaterialAnimatedSwitch
   android:id="@+id/location_switch"
   android:layout_width="0dp"
   android:layout_weight="3"
   android:layout_height="wrap_content"
   app:icon_release="@drawable/ic_location_off"
   app:icon_press="@drawable/ic_location_on"
   app:base_release_color="@color/baseReleaseColor"
   app:base_press_color="@color/basePressColor"
   app:ball_release_color="@color/ballReleaseColor"
   app:ball_press_color="@android:color/white" />
</LinearLayout>

Stacktrace:

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.payload, PID: 15360
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.payload/com.example.payload.Welcome}: android.view.InflateException: Binary XML file line #23: Binary XML file line #23: Error inflating class com.github.glomadrian.materialanimatedswitch.MaterialAnimatedSwitch
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2913)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048)
        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:1808)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:193)
        at android.app.ActivityThread.main(ActivityThread.java:6669)
        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:858)
     Caused by: android.view.InflateException: Binary XML file line #23: Binary XML file line #23: Error inflating class com.github.glomadrian.materialanimatedswitch.MaterialAnimatedSwitch
     Caused by: android.view.InflateException: Binary XML file line #23: Error inflating class com.github.glomadrian.materialanimatedswitch.MaterialAnimatedSwitch
     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.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 com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:420)
        at android.app.Activity.setContentView(Activity.java:2771)
        at com.example.payload.Welcome.onCreate(Welcome.java:77)
        at android.app.Activity.performCreate(Activity.java:7136)
        at android.app.Activity.performCreate(Activity.java:7127)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2893)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048)
        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:1808)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:193)
        at android.app.ActivityThread.main(ActivityThread.java:6669)
        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:858)
     Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'int android.graphics.Bitmap.getWidth()' on a null object reference
E/AndroidRuntime:     at android.graphics.Bitmap.createScaledBitmap(Bitmap.java:734)
        at com.github.glomadrian.materialanimatedswitch.painter.IconPainter.initBitmap(IconPainter.java:41)
        at com.github.glomadrian.materialanimatedswitch.painter.IconPainter.init(IconPainter.java:36)
        at com.github.glomadrian.materialanimatedswitch.painter.IconPainter.<init>(IconPainter.java:30)
        at com.github.glomadrian.materialanimatedswitch.painter.IconPressPainter.<init>(IconPressPainter.java:30)
        at com.github.glomadrian.materialanimatedswitch.MaterialAnimatedSwitch.initPainters(MaterialAnimatedSwitch.java:79)
        at com.github.glomadrian.materialanimatedswitch.MaterialAnimatedSwitch.init(MaterialAnimatedSwitch.java:65)
        at com.github.glomadrian.materialanimatedswitch.MaterialAnimatedSwitch.init(MaterialAnimatedSwitch.java:90)
        at com.github.glomadrian.materialanimatedswitch.MaterialAnimatedSwitch.<init>(MaterialAnimatedSwitch.java:54)
            ... 32 more
E/UncaughtException: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.payload/com.example.payload.Welcome}: android.view.InflateException: Binary XML file line #23: Binary XML file line #23: Error inflating class com.github.glomadrian.materialanimatedswitch.MaterialAnimatedSwitch
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2913)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048)
        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:1808)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:193)
        at android.app.ActivityThread.main(ActivityThread.java:6669)
        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:858)
     Caused by: android.view.InflateException: Binary XML file line #23: Binary XML file line #23: Error inflating class com.github.glomadrian.materialanimatedswitch.MaterialAnimatedSwitch
     Caused by: android.view.InflateException: Binary XML file line #23: Error inflating class com.github.glomadrian.materialanimatedswitch.MaterialAnimatedSwitch
     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.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 com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:420)
        at android.app.Activity.setContentView(Activity.java:2771)
        at com.example.payload.Welcome.onCreate(Welcome.java:77)
        at android.app.Activity.performCreate(Activity.java:7136)
        at android.app.Activity.performCreate(Activity.java:7127)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2893)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048)
        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:1808)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:193)
        at android.app.ActivityThread.main(ActivityThread.java:6669)
        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:858)
     Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'int android.graphics.Bitmap.getWidth()' on a null object reference
        at android.graphics.Bitmap.createScaledBitmap(Bitmap.java:734)
        at com.github.glomadrian.materialanimatedswitch.painter.IconPainter.initBitmap(IconPainter.java:41)
        at com.github.glomadrian.materialanimatedswitch.painter.IconPainter.init(IconPainter.java:36)
        at com.github.glomadrian.materialanimatedswitch.painter.IconPainter.<init>(IconPainter.java:30)
        at com.github.glomadrian.materialanimatedswitch.painter.IconPressPainter.<init>(IconPressPainter.java:30)
        at com.github.glomadrian.materialanimatedswitch.MaterialAnimatedSwitch.initPainters(MaterialAnimatedSwitch.java:79)
        at com.github.glomadrian.materialanimatedswitch.MaterialAnimatedSwitch.init(MaterialAnimatedSwitch.java:65)
        at com.github.glomadrian.materialanimatedswitch.MaterialAnimatedSwitch.init(MaterialAnimatedSwitch.java:90)
        at com.github.glomadrian.materialanimatedswitch.MaterialAnimatedSwitch.<init>(MaterialAnimatedSwitch.java:54)

1 个答案:

答案 0 :(得分:0)

从创建的图像类中删除了可绘制对象中的XML文件,并解决了错误