As of ADT 14, resource fields cannot be used as switch cases. invoke this fix to get more details

Source: Internet
Author: User

Public static final int main = 0x7f030004;
However, as of ADT 14, they will announce the following:

Public static int main = 0x7f030004;

Missing final in the r File

In other words, the constant not final is in the library project. The reason is simple: when multiple database projects are combined, fields with actual values (which must be unique) may collide. Before ADT 14, all fields were finals, so
All libraries must have all their resources and related Java code for re-compilation and use of the main project. This is poor performance because it makes building very slow. This also prevents database project allocation, excluding the source
Code that limits the scope of use of library projects.
The reason for the field is no longer the last one. It means that the library jar can be compiled once and reused directly in other projects. And library projects that allow distribution of binary versions (in R15), which allows faster building.

However, it has an impact on the library's source code. The following code form will not be compiled:

Int id = view. GETID (); Switch (ID ){

Case R. Id. button1:        action1();        break;    case R.id.button2:        action2();        break;    case R.id.button3:        action3();        break;}

This is because the switch statement requires all the case labels, such as R. Id. button1, which remains constant during compilation (so that the values can be directly copied to the. Class file ).
The solution to this problem is very simple: Convert the switch statement into an IF-else statement. Fortunately, this is very easy in eclipse. Just insert the keyword into the switch and press Ctrl-1 (or cmd 1 on Mac ):

In the preceding scenario, the switch statement is:

Int id = view. GETID (); If (ID = R. id. button1) {Action1 ();} else if (ID = R. id. button2) {Action2 ();} else if (ID = R. id. button3) {action3 ();}

This is usually negligible in terms of UI code and performance impact.

We have a detector that discovers these errors (an R field is referenced by an inconsistent case tag) and provides a brief description of the problem (and points to this page for more information .)

More information about the automatic detection.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.