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 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 :

  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.






Recent Posts:
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, Video Tutorials, Code Snippets, How Tos, Blogs, Articles, etc.