ZCShou/GoGoGo · error · java.lang.IllegalArgumentException

unsupported drawable type

Error message

unsupported drawable type

What it means

A deliberate type guard in RockerView.getBitmap(Context, int): the helper can only rasterize drawables that resolve to BitmapDrawable or VectorDrawable. When ContextCompat.getDrawable returns any other Drawable subclass (e.g. AnimatedVectorDrawable, ColorDrawable, or a state/layer-list wrapper), no conversion path exists and an IllegalArgumentException is thrown. It fires while init or toggleLockCtrl loads a joystick image, meaning a referenced drawable resource resolved to an unsupported type.

Solutions

  1. Replace the referenced resource with a bitmap asset (PNG/JPEG/webp) or a plain <vector> VectorDrawable.
  2. Add a branch for the actual Drawable subtype encountered (e.g. AnimatedVectorDrawable, PictureDrawable) and rasterize it instead of throwing.
  3. If the id may point to a StateListDrawable or LayerListDrawable, unwrap it (e.g. stateList.getDrawable(0)) and dispatch on the child's type.
  4. Handle the failure at the init/toggleLockCtrl call sites and fall back to a default joystick bitmap so a bad resource degrades gracefully.
Defensive patterns

Strategy: fallback

When it happens

Trigger: Thrown at app/src/main/java/com/zcshou/joystick/RockerView.java:200 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of ZCShou/GoGoGo@de0d596190 (2026-09-09). Data as JSON: /api/errors/aeb601b48194ab97. Report an issue: GitHub.

Appendix: source

Thrown at app/src/main/java/com/zcshou/joystick/RockerView.java:200

    }

    private static Bitmap getBitmap(VectorDrawable vectorDrawable) {
        Bitmap bitmap = Bitmap.createBitmap(vectorDrawable.getIntrinsicWidth(),
                vectorDrawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(bitmap);
        vectorDrawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
        vectorDrawable.draw(canvas);
        return bitmap;
    }

    private static Bitmap getBitmap(Context context, int drawableId) {
        Drawable drawable = ContextCompat.getDrawable(context, drawableId);
        if (drawable instanceof BitmapDrawable) {
            return BitmapFactory.decodeResource(context.getResources(), drawableId);
        } else if (drawable instanceof VectorDrawable) {
            return getBitmap((VectorDrawable) drawable);
        } else {
            throw new IllegalArgumentException("unsupported drawable type");
        }
    }

    private Bitmap scaleBitmap(Bitmap bitmap) {
        Matrix mMatrix = new Matrix();
        mMatrix.postScale(0.45f,0.45f);
        return Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), mMatrix,true);
    }

    private void toggleLockCtrl() {
        Bitmap bitmap;

        isAuto = !isAuto;

        if (isAuto) {
            bitmap = getBitmap(getContext(), R.drawable.ic_lock_close);
        } else {
            bitmap = getBitmap(getContext(), R.drawable.ic_lock_open);

View on GitHub (pinned to de0d596190)