Using a custom view from xml. View class cast error

559 Views Asked by At

When running my code i get a java.lang.ClassCastException: android.view.View when I initialise the XML layout for my view.

Why?

UPDATE

Problem was since I was adding a button inside a view element. Corrected this placement and it worked again

2

There are 2 best solutions below

0
On BEST ANSWER

Found my problem was elsewhere. Was adding a button inside a view element which seemed to be cause the exception.

Thanks for your help

1
On

Since we see that it can't cast to android.view.View I can only guess that AppZappy.NIRailAndBus.UI.ToggleImageButton does not extend View or a subclass of View but I would need to see the class declaration to verify that.