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.



















Copyright © Code2care 2024 | Privacy Policy | About Us | Contact Us | Sitemap