我是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)
提前谢谢。
答案 0 :(得分:0)
- 在shell或命令提示符下运行:adb kill-server
- 从设备上拔下USB电缆并重新插入。
- 打开设备视图(窗口 - >显示视图 - >其他 - > Android - >设备)
- 点击Android设备视图上的设备。
醇>
来源:MikeC:LogCat & Console stopped working with Eclipse Android Emulator