调用另一个类时出现未知错误

[英]Unknown error when calling another class


I'm new to android and I am making a app that shows a color you choose with three seekbars (RGB). I keep getting this Unexpected error from Unknown source and I have no idea what is wrong. By debugging I find that the app crashes when I either call the ChangeColor merhod or when I change the values of red, green and blue in DrawCanvas.java from RGB.java. What am I missing?

我是Android的新手,我正在制作一个应用程序,显示您使用三个搜索栏(RGB)选择的颜色。我不断从未知来源获得此意外错误,我不知道有什么问题。通过调试,我发现当我调用ChangeColor merhod或者在RGB.java中更改DrawCanvas.java中的红色,绿色和蓝色值时应用程序崩溃了。我错过了什么?

Here is all the code:

这是所有代码:

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

}

}

and the other class

和另一个班级

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;
}
}

and finally the error message:

最后是错误信息:

[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)

Thank you in advance.

先感谢您。

1 个解决方案

#1


0  

  1. In a shell or command prompt run: adb kill-server
  2. 在shell或命令提示符下运行:adb kill-server

  3. Unplug the USB cable from the device and plug it back in.
  4. 从设备上拔下USB电缆并重新插入。

  5. Open the devices view (Window -> Show View -> Other -> Android -> Devices)
  6. 打开设备视图(窗口 - >显示视图 - >其他 - > Android - >设备)

  7. Click on the device on the android devices view.
  8. 单击android设备视图上的设备。

Credit: MikeC : LogCat & Console stopped working with Eclipse Android Emulator

图片来源:MikeC:LogCat和Console停止使用Eclipse Android Emulator


注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2012/10/15/af19d635dc3024dfcbf34d31da6b4cc.html



 
  © 2014-2022 ITdaan.com 联系我们: