I have used switch widget in my application. when I run app on lollipop, its working fine with it. but when I run in kitkat version, its going to crash.
xml design:
<Switch
android:id="@+id/act_edit_device_swtch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:switchMinWidth="40sp"
android:thumb="@null"
android:track="@drawable/switchdb" />
switchdb.xml
<?xml version="1.0" encoding="UTF-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/onswitch" android:state_checked="true"/>
<item android:drawable="@drawable/offswitch" android:state_checked="false"/>
<item android:drawable="@drawable/offswitch"></item>
</selector>
below is my crash report:
java.lang.NullPointerException
at android.widget.Switch.jumpDrawablesToCurrentState(Switch.java:825)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5500)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5500)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5500)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5500)
at android.widget.FrameLayout.jumpDrawablesToCurrentState(FrameLayout.java:189)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5500)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5500)
at android.widget.FrameLayout.jumpDrawablesToCurrentState(FrameLayout.java:189)
at android.view.View.onAttachedToWindow(View.java:12146)
at android.view.ViewGroup.onAttachedToWindow(ViewGroup.java:3499)
at com.android.internal.policy.impl.PhoneWindow$DecorView.onAttachedToWindow(PhoneWindow.java:2659)
at android.view.View.dispatchAttachedToWindow(View.java:12620)
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2460)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1236)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1019)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5725)
Use android:thumb="@android:color/transparent"
instead of @null
If not use "android:track" property, And Use android:track="@android:color/transparent" instead of @null
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With