# Error message about 'DrawableCompat'

**URL:** <https://discourse.processing.org/t/error-message-about-drawablecompat/40183>\
**Category:** Processing for Android\
**Created:** [December 16, 2022, 1:27pm UTC](https://discourse.processing.org/t/error-message-about-drawablecompat/40183 "2022-12-16T13:27:03Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![David](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/david/32/8853_2.png) [@David](https://discourse.processing.org/u/David)\
**Post date:** [December 16, 2022, 1:27pm UTC](https://discourse.processing.org/t/error-message-about-drawablecompat/40183/1 "2022-12-16T13:27:04Z")

</div>

I’m trying to run the “androidWidgets” example, and I’m getting an error message on a couple of lines, which I don’t understand. The example works, though, so I guess they’re just warning messages. The error message is:

`The name "DrawableCompat" cannot recognized`

The lines getting the error are in the Switch tab, lines 28 and 29:

```auto
int[][] states = new int[][]{
  new int[] {-android.R.attr.state_checked},
  new int[] {android.R.attr.state_checked},
};

int[] thumbColors = new int[] {
  Color.WHITE,
  Color.GREEN,
};

int[] trackColors = new int[] {
  Color.WHITE,
  Color.WHITE,
};

void switchBtn(int x, int y) {  
  Switch switchBtn = new Switch(activity);
  LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
  layoutParams.setMargins(x, y, 200, 190);
  switchBtn.setLayoutParams(layoutParams);
  switchBtn.setText("OFF");
  switchBtn.setScaleX(2.0);
  switchBtn.setScaleY(2.0);
  FrameLayout layout = (FrameLayout)activity.findViewById(R.id.content);
  layout.addView(switchBtn);
DrawableCompat.setTintList(DrawableCompat.wrap(switchBtn.getThumbDrawable()), new ColorStateList(states, thumbColors));
DrawableCompat.setTintList(DrawableCompat.wrap(switchBtn.getTrackDrawable()), new ColorStateList(states, trackColors));
  switchBtn.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
    void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
      String msg = isChecked ? "ON" : "OFF";
      switchBtn.setText(msg);
      println("switch btn = ",msg);
    }
  }
  );
}

```

In the main tab, there’s an import statement:

`import androidx.core.graphics.drawable.DrawableCompat;`

Can anyone explain what the error message means? Is there something wrong with the import statement? Or is there a problem with the two lines that reference ‘DrawableCompat’?

Thanks.

---

<div class="post-metadata">

**Author:** ![svan](https://avatars.discourse-cdn.com/v4/letter/s/82dd89/32.png) [@svan](https://discourse.processing.org/u/svan)\
**Post date:** [December 16, 2022, 10:34pm UTC](https://discourse.processing.org/t/error-message-about-drawablecompat/40183/2 "2022-12-16T22:34:19Z")

</div>

Error message is due to ‘No library found for androidx.core.graphics.drawable’  
Try this code instead and delete _import androidx.core.graphics.drawable.DrawableCompat;_

```auto
int[][] states = new int[][]{
  new int[] {-android.R.attr.state_checked},
  new int[] {android.R.attr.state_checked},
};

int[] thumbColors = new int[] {
  Color.WHITE,
  Color.GREEN,
};

int[] trackColors = new int[] {
  Color.WHITE,
  Color.WHITE,
};

void switchBtn(int x, int y) {  
  Switch switchBtn = new Switch(activity);
  LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
  layoutParams.setMargins(x, y, 200, 190);
  switchBtn.setLayoutParams(layoutParams);
  switchBtn.setText("OFF");
  switchBtn.setScaleX(2.0);
  switchBtn.setScaleY(2.0);
  FrameLayout layout = (FrameLayout)activity.findViewById(R.id.content);
  layout.addView(switchBtn);
  switchBtn.setThumbTintList(new ColorStateList(states, thumbColors));
  switchBtn.setTrackTintList(new ColorStateList(states, trackColors));
  switchBtn.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
    void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
      String msg = isChecked ? "ON" : "OFF";
      switchBtn.setText(msg);
      println("switch btn = ",msg);
    }
  }
  );
}

```

---

<div class="post-metadata">

**Author:** ![David](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/david/32/8853_2.png) [@David](https://discourse.processing.org/u/David)\
**Post date:** [December 17, 2022, 4:00pm UTC](https://discourse.processing.org/t/error-message-about-drawablecompat/40183/3 "2022-12-17T16:00:55Z")

</div>

Thanks, that got rid of the error messages. But why didn’t I get an error message on the import statement itself, if it couldn’t be found?

---

<div class="post-metadata">

**Author:** ![svan](https://avatars.discourse-cdn.com/v4/letter/s/82dd89/32.png) [@svan](https://discourse.processing.org/u/svan)\
**Post date:** [December 17, 2022, 4:40pm UTC](https://discourse.processing.org/t/error-message-about-drawablecompat/40183/4 "2022-12-17T16:40:15Z")

</div>

`But why didn’t I get an error message on the import statement itself, if it couldn’t be found?`

It was at the top of the console log on my system; you probably missed it.
