0

I am a beginner in android programme development...however I am given a task to develop an oscilloscope in android phone..I have got some program when I debugging the program. I have set the button for the oscilloscope using these code..

run_buton = (ToggleButton) findViewById(R.id.tbtn_runtoggle);
    run_buton.setOnClickListener(this);
    rb1 = (RadioButton)findViewById(R.id.rbtn_ch1);
    rb2 = (RadioButton)findViewById(R.id.rbtn_ch2);

and

public static final int rbtn_ch1 = 0;
public static final int rbtn_ch2 = 0;
public static final int txt_ch1pos = 0;
public static final int txt_ch2pos = 0;
public static final int button_connect = 0;
public static final int WaveformArea = 0;
public static int btn_position_down;
public static int tbtn_runtoggle;
public static int btn_position_up;
btn_pos_up = (Button) findViewById(R.id.btn_position_up);
btn_pos_down = (Button) findViewById(R.id.btn_position_down);
btn_pos_up.setOnClickListener(this);
btn_pos_down.setOnClickListener(this);

and I set all things after R.id. to be an integer/field.. which shown in R file as below

however Eclispe told me that I have got program on the last three field...that are "btn_posiion_down","tbtn_runtoggle" and "btn_postion_up".. it shows error, saying that "case expression should be constant expressions"...i dont understand what it means...The first sentence of the script gets the error...

case R.id.btn_position_up :
        if(rb1.isChecked() && (ch1_pos<38) ){
            ch1_pos += 1; ch1pos_label.setPadding(0, toScreenPos(ch1_pos), 0, 0);
            sendMessage( new String(new byte[] {ADJ_POSITION, CHANNEL1, ch1_pos}) );
        }
        else if(rb2.isChecked() && (ch2_pos<38) ){
            ch2_pos += 1; ch2pos_label.setPadding(0, toScreenPos(ch2_pos), 0, 0);
            sendMessage( new String(new byte[] {ADJ_POSITION, CHANNEL2, ch2_pos}) );
        }
        break;

May anyone kindly tells me what happens??

thumbmunkeys
  • 20,606
  • 8
  • 62
  • 110
  • Hi i am developing an app for audio recording with oscilloscope. i do not know how to get oscilloscope. please provide some sample code. thanks. – M.A.Murali Jun 06 '12 at 15:46

1 Answers1

1

It sounds as if you are using a library project that defines those ids. If that is the case, you can't use switch statements with those id's because they aren't static final.

Try using if/else statements instead of a switch. Eclipses Quick-Fix tool will suggest that for you as a fix for your problem.

Justin Breitfeller
  • 13,737
  • 4
  • 39
  • 47
  • I have to correct all static final above? or only those with errors? I have used quick fix..and it suggests me to turn it into integer/field...- -and still gets errors afterwards – Chun Wai Wong Feb 14 '12 at 16:50
  • instead of using "case R.id.btn_position_up" use if(id == R.id.btn_position_up) – Justin Breitfeller Feb 15 '12 at 19:17
  • Hi i am developing an app for audio recording with oscilloscope. i do not know how to get oscilloscope. please provide some sample code. thanks. – M.A.Murali Jun 06 '12 at 15:46
  • @murali_ma maybe ask a new question instead of posting a comment here randomly – dymmeh Jun 07 '12 at 13:34