Android Error Unexpected cast to Button: layout tag was FrameLayout
This is an Android Lint WrongViewCast Error message, what this error means is that you have cast a layout as a Button.
Example :
Suppose there is Button in your layout.xml file say button1 wrapped within a LinearLayout with id layout.
Now in your Java Class you have referred to the button by R.id.layout instead of R.id.button.
Button btn = (Button) findViewById(R.id.layout);
Should be;
Button btn = (Button) findViewById(R.id.button);
If you think you need such functionality you can simple suppress this Error message to a warning or information.
Steps :
- Goto : Menu -> Window (Eclipse on Mac) -> Preferences -> Lint Error Checking
- Now look for issue : WrongViewCast and change their severity from Fatal to Warning
- Apply, now this error message will be displayed as warning.
Provide Feedback For This Article
We take your feedback seriously and use it to improve our content. Thank you for helping us serve you better!
😊 Thanks for your time, your feedback has been registered!
Comments & Discussion
Facing issues? Have questions? Post them here! We're happy to help!