I am using Butter Knife in my project along with the Material Design Libraries for the UI.
When attempting to create buttons using the Material Design Library i get a 'Class Cast Exception' because of the usage of Butter Knife.
Is there a way to fix this?
MainActivity.Java
@Bind(R.id.switch1) Switch switch;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ButterKnife.bind(this);
}
XML Switch Layout
<com.gc.materialdesign.views.Switch
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/switch1"
android:layout_centerHorizontal="true" />
Errors
Caused by: java.lang.RuntimeException: Unable to bind views for com.example.MainActivty
Caused by: java.lang.ClassCastException:com.gc.materialdesign.views.Switch cannot be cast to android.widget.Switch
You are importing the wrong Switch
- instead of importing android.widget.Switch
, you need to import com.gc.materialdesign.views.Switch
and use that class when defining your switch
variable.