hello guys, got this code but it has an error.

any ideas? Thanks.

public void ListenerCheckAll() {

        Chbox0 = (CheckBox) findViewById(R.id.checkBox1);

        xAllButton = (Button) findViewById(R.id.button1);


        xAllButton.setOnClickListener(new OnClickListener() {  

            @Override   
            public void onClick(View vx) {

                Chbox0 = (CheckBox) findViewById(R.id.checkBox1);


                 boolean checked = ((CheckBox) vx).isChecked();

                       //this part has the error
                    switch(vx.getId()){
                case R.id.CheckBox01:
                    if (checked){
                     Toast.makeText(ChTxtMainActivity.this,
                      "CheckBox1 is checked", Toast.LENGTH_SHORT).show();
                       edTxt1.setEnabled(false);
                      break;
                    }
                      }  

           }


         });

        }

Recommended Answers

With your number of posts you should know better then just drop code with no exact error

Jump to Post

All 3 Replies

With your number of posts you should know better then just drop code with no exact error

hi peter, log cat error actually is quite useless. i run it through the emulator the error message is quite general (not a specific error).

Just realised you are using switch statment and validating view ID. This is no longer safe. If you need to do that you should then doing it from if/else

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.