我是一个安卓程序的初学者,development...however,我的任务是在安卓手机上开发一个示波器,我有一些程序,当我调试程序。我已经使用这些代码设置了示波器的按钮。
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);和
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);我把所有的东西都设置在R.id之后。为整数/字段..在R文件中显示,如下所示
然而,Eclispe告诉我,我有关于最后三个field...that的程序是"btn_posiion_down","tbtn_runtoggle“和"btn_postion_up"..它显示了错误,说"case表达式应该是常量表达式“...i不明白它是什么,脚本的第一句话得到了错误...
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;有人能告诉我发生了什么事吗?
发布于 2012-02-15 00:34:54
听起来像是在使用定义这些if的库项目。如果是这种情况,您不能对这些id使用switch语句,因为它们不是静态的final。
尝试使用if/else语句而不是switch。Eclipses - fix工具将为您提供建议,以解决您的问题。
https://stackoverflow.com/questions/9280428
复制相似问题