java.lang.NullPointerException
at android.widget.Switch.jumpDrawablesToCurrentState(Switch.java:825)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5158)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5158)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5158)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5158)
at android.widget.FrameLayout.jumpDrawablesToCurrentState(FrameLayout.java:189)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5158)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5158)
at android.widget.FrameLayout.jumpDrawablesToCurrentState(FrameLayout.java:189)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5158)
at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5158)
at android.widget.FrameLayout.jumpDrawablesToCurrentState(FrameLayout.java:189)
at android.view.View.onAttachedToWindow(View.java:11583)
at com.android.internal.policy.impl.PhoneWindow$DecorView.onAttachedToWindow(PhoneWindow.java:2463)
at android.view.View.dispatchAttachedToWindow(View.java:11960)
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2415)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1195)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:992)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4355)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
at android.view.Choreographer.doCallbacks(Choreographer.java:562)
at android.view.Choreographer.doFrame(Choreographer.java:532)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735)
at android.os.Handler.handleCallback(Handler.java:728)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:138)
at android.app.ActivityThread.main(ActivityThread.java:5089)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
at dalvik.system.NativeStart.main(Native Method)
这个异常,是因为我们使用Switch这个控制的时候,不规范导致,我们会这样写:(这个在高版本android上不会出错)
<Switch
android:id="@+id/autoConnect"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:background="@drawable/cb_switch_blue"
android:text=""
android:textOff=""
android:textOn=""
android:thumb="@null"
android:track="@null" />
正是其中的那个null导致了这个问题,解决办法是,不要用null,如下使用透明代替
<Switch
android:id="@+id/autoConnect"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:background="@drawable/cb_switch_blue"
android:text=""
android:textOff=""
android:textOn=""
android:thumb="@android:color/transparent"
android:track="@android:color/transparent" />