1

我正在完成我的项目,但一直遇到这个错误。我不明白,因为 PermutationData 是另一个具有静态 String[][] ROTOR_SPECS (一个数组)的类,我正在检查元素 x[0] 是否在 PermutationData 内部,但我的编译器一直将 PermutationData 识别为一个变量,而不是一堂课....我现在在我的转子班里。

Rotor.java:90:错误:找不到符号

for (String[] x : PermutationData.ROTOR_SPECS) {
                  ^
symbol: variable PermutationData
location: class Rotor
        if (type() == x[0]) {
            Index1 = toIndex(x[1].charAt(p));

这是我的 PermutationData.java 类。

class PermutationData {

/** The names and definitions of the rotors and reflectors in M4.  The
 *  first string in each entry is the name of a rotor or reflector.  The
 *  second is a 26-character string whose first character is the mapping
 *  (when the rotor is at the 'A' setting), of 'A' in the right-to-left
 *  direction, whose second is that of 'B', etc.
 *
 *  The third entry, if present, is the inverse of the
 *  second---the left-to-right permutation of the rotor.  It is
 *  not present for reflectors.
 *
 *  The fourth entry, if present, gives the positions of the
 *  notches. These are the settings of the rotors just before the
 *  wheels advanced (wheels advance before a character is
 *  translated).  Other written accounts of the Enigma generally
 *  show instead the character settings just after a character is
 *  coded (e.g., 'R', rather than 'Q', or 'A' rather than 'Z').
 *  The entry is absent in rotors that do not advance. */

static final String[][] ROTOR_SPECS = {
    { "I", "EKMFLGDQVZNTOWYHXUSPAIBRCJ", "UWYGADFPVZBECKMTHXSLRINQOJ",
      "Q" },
    { "II", "AJDKSIRUXBLHWTMCQGZNPYFVOE", "AJPCZWRLFBDKOTYUQGENHXMIVS",
      "E" },
    { "III", "BDFHJLCPRTXVZNYEIWGAKMUSQO", "TAGBPCSDQEUFVNZHYIXJWLRKOM",
      "V" },
    { "IV", "ESOVPZJAYQUIRHXLNFTGKDCMWB", "HZWVARTNLGUPXQCEJMBSKDYOIF",
      "J" },
    { "V", "VZBRGITYUPSDNHLXAWMJQOFECK", "QCYLXWENFTZOSMVJUDKGIARPHB",
      "Z" },
    { "VI", "JPGVOUMFYQBENHZRDKASXLICTW", "SKXQLHCNWARVGMEBJPTYFDZUIO",
      "ZM" },
    { "VII", "NZJHGRCXMYSWBOUFAIVLPEKQDT", "QMGYVPEDRCWTIANUXFKZOSLHJB",
      "ZM" },
    { "VIII", "FKQHTLXOCBJSPDZRAMEWNIUYGV", "QJINSAYDVKBFRUHMCPLEWZTGXO",
      "ZM" },
    { "BETA", "LEYJVCNIXWPBQMDRTAKZGFUHOS", "RLFOBVUXHDSANGYKMPZQWEJICT" },
    { "GAMMA", "FSOKANUERHMBTIYCWLQPZXVGJD", "ELPZHAXJNYDRKFCTSIBMGWQVOU" },
    { "B", "ENKQAUYWJICOPBLMDXZVFTHRGS" },
    { "C", "RDOBJNTKVEHMLFCWZAXGYIPSUQ" }
};

}

4

3 回答 3

3

如果ROTOR_SPECS确实是一种方法,则应使用方括号调用它:PermutationData.ROTOR_SPECS()

否则编译器认为它是一个变量!

于 2013-09-28T03:24:33.943 回答
0

除了@alfasin 的回答,请确保您已导入 PermutationData

于 2013-09-28T03:36:18.433 回答
0

我认为您的 PermutationData.java 类具有默认级别的包访问权限,并且您正在从其他包中调用它。因为无法访问这个 PermutationData.java 类。

请公开 PermutationData.java 可以解决您的问题。

另一件事是,ROTOR_SPECS 是一个 String[][] 类型的变量。所以您可以先将它存储在程序中的某个位置,然后将其分配给其他变量,然后检查它是否存在。

尝试运行它。它正在工作。

for (String[] x : PermutationData.ROTOR_SPECS) {  
             System.out.println(x[0]);
}
于 2013-09-28T04:41:28.517 回答