Java – duplicate case label

I found some time ago a function to replace polish characters in text with “normal” version of this character. I used this in some projects earlier without problems, but now, when i just copied it, this doesn’t want to work. But when I try to compile old projects in the same IDE(IntelliJ IDEA 14.1.3) it is ok, but in new project it’s giving me errors:

Error:(22, 17) java: duplicate case label

It happens for each case except first and default. Function code:

public static String polskieznaki(String s)
{
    char[] tekst = s.toCharArray();
    s = "";

    for(int i=0; i<tekst.length; i++)
    {

        switch(tekst[i])

        {

            case 'ą': tekst[i] = 'a'; break;

            case 'ć': tekst[i] = 'c'; break;

            case 'ę': tekst[i] = 'e'; break;

            case 'ó': tekst[i] = 'o'; break;

            case 'ś': tekst[i] = 's'; break;

            case 'ł': tekst[i] = 'l'; break;

            case 'ż': tekst[i] = 'z'; break;

            case 'ź': tekst[i] = 'z'; break;

            case 'ń': tekst[i] = 'n'; break;

            case 'Ą': tekst[i] = 'A'; break;

            case 'Ć': tekst[i] = 'C'; break;

            case 'Ę': tekst[i] = 'E'; break;

            case 'Ó': tekst[i] = 'O'; break;

            case 'Ś': tekst[i] = 'S'; break;

            case 'Ł': tekst[i] = 'L'; break;

            case 'Ż': tekst[i] = 'Z'; break;

            case 'Ź': tekst[i] = 'Z'; break;

            case 'Ń': tekst[i] = 'N'; break;

            default: break;

        }
        s += tekst[i];

    }

    return s;
}

I would be grateful for any help.

Answer

Thanks to Makoto’s comment, I set the default encoding of this particular file (not just the IDE and Project Encoding) to UTF-8 and this fixed the problem.

Leave a Reply

Your email address will not be published. Required fields are marked *