Android switch statement case expressions must is constant expressions

Source: Internet
Author: User

In the project encountered such exception: caseexpressions must is constant expressions

public class Standingcityactivity extends Activity implements view.onclicklistener{}

  @Override public    void OnClick (View v) {        switch (V.getid ()) {        r.id.back: Break                        ;        Default: Break            ;        }    }

From the syntax, logic above, there is no problem, but eclipse error ~ ~ ~

Baidu on the Internet to find solutions, the vast number of programmers comrades to provide a solution

http://blog.csdn.net/aaawqqq/article/details/20037407

The main reason is that the current project is a result of the library being referenced by other projects.

Feeling a little puzzled, estimating the relationship with Eclipse support? Or whatever it is, it's not.

One solution is to remove the option from the IS library in the project configuration in eclipse

Another workaround is to set listener for each control individually:

        Back.setonclicklistener (New View.onclicklistener () {                        @Override public            void OnClick (View v) {                //TODO auto-generated method Stub                            }        });

Add:

When the current project is set to the library, all switch is not available.

Android switch statement case expressions must is constant expressions

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.