Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

177
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!