无法访问的语句错误;在问题点之前没有无限循环或 Return 语句

Unreachable Statement Error; No Infinite Loops or Return Statements Prior to the point of issue

我在以下两行代码中出现无法访问的语句错误:

System.out.println("We Made It!");

                switch (runs[i].charAt(2)) {
                    case 'A':
                        tempData.add((byte) 0xA); //0b1010);
                        continue;
                        //if hexadecimal is 11 concatenate an "a" to the string
                    case 'B':
                        tempData.add((byte) 0xB);//0b1011);
                        continue;
                        //if hexadecimal is 12 concatenate an "a" to the string
                    default:
                        continue;

我怀疑问题出在 switch 语句之后的代码无法访问。如何让无法访问的 switch 语句在 else 语句中的第一个语句之后执行?

这是整个方法:

public static byte[] stringToRle(String rleString) {
    //variable declarations
    String[] runs = rleString.split(":");
    ArrayList<Byte> tempData = new ArrayList<Byte>();

    //start of for loop
    //iterate through every element of the loop
    for (int i = 0; i < runs.length; i++) {
        //if the string in the array has a length of 2, execute the following code
        if (runs[i].length() == 2) {
        //execute the switch statement twice, once for each letter of the two letter string    
            for(int j = 0; j < runs[i].length(); j++) {
                switch (runs[i].charAt(j)) {
                    case '0':
                        tempData.add((byte) 0x0);
                        continue;
                    case '1':
                        tempData.add((byte) 0x1);
                        continue;
                    case '2':
                        tempData.add((byte) 0x2);
                        continue;
                    default:
                        continue;
                }
            }
        }
        //if the string in the array has a length of 3, execute the following code
        else if(runs[i].length() == 3) {
                //the following code executes fine
                switch (runs[i].charAt(1)) {
                    case '0':
                        tempData.add((byte) 0xA);
                        continue;
                    case '1':
                        tempData.add((byte) 0xB);
                        continue;
                    case '2':
                        tempData.add((byte) 0xC);
                        continue;
                    default:
                        continue;
                }
                //FIRST UNREACHABLE STATEMENT
                //FIRST UNREACHABLE STATEMENT
                //FIRST UNREACHABLE STATEMENT
                //FIRST UNREACHABLE STATEMENT
                //FIRST UNREACHABLE STATEMENT
                switch (runs[i].charAt(2)) {
                    case 'A':
                        tempData.add((byte) 0xA); //0b1010);
                        continue;
                        //if hexadecimal is 11 concatenate an "a" to the string
                    case 'B':
                        tempData.add((byte) 0xB);//0b1011);
                        continue;
                        //if hexadecimal is 12 concatenate an "a" to the string
                    default:
                        continue;
                }
            //SECOND UNREACHABLE STATEMENT
            //SECOND UNREACHABLE STATEMENT
            //SECOND UNREACHABLE STATEMENT
            //SECOND UNREACHABLE STATEMENT
            //SECOND UNREACHABLE STATEMENT
            System.out.println("We Made It!");
        }
    }
    byte[] array = new byte[tempData.size()];
    for(int i = 0; i < array.length; i++) {
        array[i] = tempData.get(i);
        System.out.println(" " + array[i]);
    }
    return array;
}

continue for for 循环。当您在 switch 个案例中使用它时。因此,当您在每个 switch case 中放置 continue 时,它​​会继续 for 循环。下面的代码根本不会执行。因为 switch 中的每一次 continue 实际上都是在重新开始循环。

看来您需要在 switch 案件中使用 break 而不是 continue 才能破案。