在Android 5.0中点击我的应用程序中的开关时,应用程序崩溃并显示如下所示的logcat.logcat不会在其中的任何位置引用我的代码,并且此开关在所有先前版本上都运行良好.除了背景颜色外,开关看起来不可见,只有在点击后才会崩溃.
经过测试,无论我是否定义了setOnCheckedChangeListener函数,都会发生同样的事情.即使开关在布局中但从未在代码中,它仍然会在单击时崩溃.
其中一个开关:
<Switch
android:layout_width="90dp"
android:layout_height="wrap_content"
android:textOff="Airborn"
android:textOn="Direct Contact"
android:textAppearance="?android:attr/textAppearanceMedium"
android:id="@+id/switchWind"/>
Run Code Online (Sandbox Code Playgroud)
这是我如何引用它.
// Doesn't actually matter since same thing happens without this
Switch sWind = (Switch) findViewById(R.id.switchWind);
sWind.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton v, boolean isChecked) {
// Won't reach here
}
});
Run Code Online (Sandbox Code Playgroud)
logcat的:
11-17 22:09:18.722 30190-30190/com.egondev.android.patientzerotest E/InputEventReceiver? Exception dispatching input event.
11-17 22:09:18.722 30190-30190/com.egondev.android.patientzerotest E/MessageQueue-JNI? Exception in MessageQueue callback: handleReceiveCallback
11-17 22:09:18.735 30190-30190/com.egondev.android.patientzerotest E/MessageQueue-JNI? java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.graphics.drawable.Drawable.getPadding(android.graphics.Rect)' on a null object reference
at …Run Code Online (Sandbox Code Playgroud)