膨胀 MaterialAnimatedSwitch 时出错

Error inflating MaterialAnimatedSwitch

我正在构建一个应用程序,我在其中使用了 glomadrain 的动画切换按钮。 完成编码后出现以下错误:

at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410) 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:750) 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.(IconPainter.java:30) 11-25 14:05:04.032 4625-4625/com.example.surajnath.taproute E/AndroidRuntime: at com.github.glomadrian.materialanimatedswitch.painter.IconPressPainter.(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.(MaterialAnimatedSwitch.java:54)

这是我关于地图和开关的代码:

<com.github.glomadrian.materialanimatedswitch.MaterialAnimatedSwitch
    android:layout_width="0dp"
    android:layout_weight="3"
    android:id="@+id/location_switch"
    android:layout_height="wrap_content"
    app:icon_release="@drawable/ic_location_off_black_24dp"
    app:icon_press="@drawable/ic_location_on_black_24dp"
    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"/>

问题是,您使用矢量可绘制对象作为 app:icon_pressapp:icon_release 的输入,而库不支持矢量可绘制对象。

您必须在创建 Bitmap 时分叉库并执行 ,或者您可以提供非矢量可绘制对象作为这些参数的输入。