我是 android 新手,我正在制作一个应用程序,该应用程序显示您使用三个搜索栏 (RGB) 选择的颜色。我不断从未知来源收到这个意外错误,我不知道出了什么问题。通过调试,我发现当我调用 ChangeColor merhod 或从 RGB.java 更改 DrawCanvas.java 中的红色、绿色和蓝色的值时,应用程序崩溃了。我错过了什么?
这是所有代码:
public class RGB extends Activity implements OnSeekBarChangeListener {
private int RED_value = 0;
private int BLUE_value = 0;
private int GREEN_value = 0;
private SeekBar sbR, sbB, sbG;
private TextView labelR, labelG, labelB;
public DrawCanvas draw;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_rgb);
labelR = (TextView)findViewById(R.id.textView4);
labelG = (TextView)findViewById(R.id.textView5);
labelB = (TextView)findViewById(R.id.textView6);
sbR = (SeekBar)findViewById(R.id.seekBar1);
sbG = (SeekBar)findViewById(R.id.seekBar2);
sbB = (SeekBar)findViewById(R.id.seekBar3);
draw = (DrawCanvas)findViewById(R.id.SurfaceView01);
sbG.setOnSeekBarChangeListener(this);
sbR.setOnSeekBarChangeListener(this);
sbB.setOnSeekBarChangeListener(this);
}
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
// TODO Auto-generated method stub
if (seekBar==sbR)
{
RED_value = progress;
labelR.setText(""+progress);
}
else if (seekBar==sbB)
{
BLUE_value = progress;
labelB.setText(""+progress);
}
else
{
GREEN_value = progress;
labelG.setText(""+progress);
}
//This is where the app crashes
draw.red = RED_value;
draw.green = GREEN_value;
draw.blue = BLUE_value;
}
public void onStartTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
public void onStopTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
}
和其他班级
public class DrawCanvas extends View {
public int red=200, green=100, blue=0;
public DrawCanvas(Context context) {
super(context);
// TODO Auto-generated constructor stub
}
public DrawCanvas(Context context, AttributeSet attrs){
super(context);
// TODO Auto-generated constructor stub
}
public DrawCanvas(Context context, AttributeSet attrs, int defStyle){
super(context);
// TODO Auto-generated constructor stub
}
protected void onDraw(Canvas c)
{
super.onDraw(c);
int color = Color.argb(255,red,green,blue);
Paint paint = new Paint();
paint.setStyle(Paint.Style.FILL);
paint.setColor(color);
c.drawPaint(paint);
}
public void ChangeColor(int r, int g, int b)
{
red = r;
green = g;
blue = b;
}
}
最后是错误消息:
[2012-10-15 00:55:24 - Unexpected error while launching logcat. Try reselecting the device.] device not found
com.android.ddmlib.AdbCommandRejectedException: device not found
at com.android.ddmlib.AdbHelper.setDevice(AdbHelper.java:752)
at com.android.ddmlib.AdbHelper.executeRemoteCommand(AdbHelper.java:373)
at com.android.ddmlib.Device.executeShellCommand(Device.java:462)
at com.android.ddmuilib.logcat.LogCatReceiver$1.run(LogCatReceiver.java:109)
at java.lang.Thread.run(Unknown Source)
先感谢您。