0

私はアンドロイドが初めてで、3 つのシークバー (RGB) で選択した色を表示するアプリを作成しています。不明なソースからこの予期しないエラーが発生し続け、何が問題なのかわかりません。デバッグすると、ChangeColor merhod を呼び出すか、DrawCanvas.java の赤、緑、青の値を RGB.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)

前もって感謝します。

4

1 に答える 1

0
  1. シェルまたはコマンド プロンプトで次を実行します: adb kill-server
  2. デバイスから USB ケーブルを取り外し、再度接続します。
  3. デバイス ビューを開きます (ウィンドウ -> ビューの表示 -> その他 -> Android -> デバイス)。
  4. Android デバイス ビューでデバイスをクリックします。

クレジット: MikeC : LogCat とコンソールが Eclipse Android Emulator で動作しなくなった

于 2012-10-15T01:30:04.750 に答える