Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

183
Vistas
Android Studio Switch label is unreachable for no apparent reason

I'm currently trying to use a switch case statement to convert some color values in Android studios but I keep on getting marked as 'Switch Label is Unreachable'. I've tried recreating a new switch case statement and even restarting Android studio, but the problem persists.

I'm genuinely at a loss for what to do. I don't see anything that would make these statements unreachable.

Here's the aforementioned code down below:

public int getColorHex(int color)
    {
        int r = (Color.red(color) << 16) & 0x00FF0000;
        int g = (Color.green(color) << 8) & 0x0000FF00;
        int b = Color.blue(color) & 0x000000FF;

        int colorValue = 0xFF000000 | r | g | b;
        int hexValue;

        switch (colorValue) {
            case 0x000000:
                hexValue = 0;
                break;

            case 0xFFFFFF:
                hexValue = 1;
                break;

            case 0x00FF00:
                hexValue = 2;
                break;

            case 0x0000FF:
                hexValue = 3;
                break;

            case 0xFF0000:
                hexValue = 4;
                break;

            case 0xFFFF00:
                hexValue = 5;
                break;

            case 0xFF8000:
                hexValue = 6;
                break;

            case 0xFFDCC8:
                hexValue = 7;
                break;

            default:
                hexValue = 8;
                break;
        }

        return hexValue;
    }

Here's also a screenshot of the warning message Android Studio gives me.

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

According to your code the high byte of colorValue is always 0xFF.

int colorValue = 0xFF000000 | r | g | b;

But in your switch cases (except 'default') the high byte is 0. So these cases are impossible to hit.

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda