表达式的类型必须是数组类型但它解析为 List<String>

The type of the expression must be an array type but it resolved to List<String>

我收到这条消息:

The type of the expression must be an array type but it resolved to List

错误出现在for这部分循环中:

for(int i = 0; i < 10; i++) {
    int nomeSorteado = gerador.nextInt(nomes.size() - 1);
    nomesSorteados[i] = nomes[nomeSorteado];
}

nomesSorteados[i] = nomes[nomeSorteado];部分是错误的行。感谢您的帮助。

您的 nomesSorteadosnomes 似乎是 List 类型。您不能使用 [index] 下标索引列表,但您可以在其上调用 get/add 方法。

for(int i = 0; i < 10; i++) {
    int nomeSorteado = gerador.nextInt(nomes.size() - 1);
    nomesSorteados.add(nomes.get(nomeSorteado));
}