Android Error Unexpected cast to Button: layout tag was FrameLayout

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 instead of

Button btn = (Button) findViewById(;

Should be;

Button btn = (Button) findViewById(;

If you think you need such functionality you can simple suppress this Error message to a warning or information.

Steps :

  1. Goto : Menu -> Window (Eclipse on Mac) -> Preferences -> Lint Error Checking

  2. Now look for issue : WrongViewCast and change their severity from Fatal to Warning

  3. Apply, now this error message will be displayed as warning.

Try Out Code2care Dev Tools:


#Android #Java #Linux #Microsoft #Google #Python #MacOS #Notepad++ #Microsoft Teams #CSS #PHP #SharePoint #Html #Linux #C-Program #Bootstrap #jQuery #Sublime #Android-Studio #Facebook #Eclipse #WhatsApp #News #MySQL #Json #HowTos #JavaScript #FTP #S3


Code2care is an initiative to publish and share varied knowledge in programming and technical areas gathered during day-to-day learnings and development activities.

Students and Software Developers can leverage this portal to find solutions to their various queries without re-inventing the wheel by referring to our easy to understand posts. Technical posts might include Learnings, Tutorials, Trouble-Shooting steps, Video Tutorials, Code Snippets, How Tos, Blogs, Articles, etc.
🎉 We are celebrating the 10th years of Code2care! Thank you for all your support! We hope we made a difference.
We strong support Gender Equality & Diversity.

We stand in solidarity with Ukraine - Make a donation to UNHCR -