为什么这是一个“找不到符号”的错误?

时间:2013-09-28 03:21:29

标签: java

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

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" }
};

}

3 个答案:

答案 0 :(得分:4)

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

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

答案 1 :(得分:0)

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

答案 2 :(得分:0)

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

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

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

尝试并运行它。它正在运行。

for (String[] x : PermutationData.ROTOR_SPECS) {  
             System.out.println(x[0]);
}