0

我目前正在使用并enum帮助在我的代码中存储多个变量,但是当我尝试从我的文本文件中读取它们时,它似乎没有设置整数。

我感到困惑和完全困惑,我不明白为什么这不起作用。

如果有人能告诉我原因,这是我的代码:

public static void readFile() {
    try {
        BufferedReader DesterationReader = new BufferedReader(new FileReader("Desteration/desteration.txt/"));
        String seperator = "";

        while ((seperator = DesterationReader.readLine()) != null)
        {
            try
            {
                String[] var3 = seperator.split(":");

                    if (var3[0].equals("Gui"))
                    {
                        Desteration.DesterationHacks.Gui.setKeybind(Integer.parseInt(var3[1]));
                        System.out.println("Setting Gui Keybind " + Integer.parseInt(var3[1]));
                    }

                    if (var3[0].equals("Xray"))
                    {
                        Desteration.DesterationHacks.Xray.setKeybind(Integer.parseInt(var3[1]));
                        System.out.println("Setting Xray Keybind " + var3[1]);
                    }

                    if (var3[0].equals("Fullbright"))
                    {
                        Desteration.DesterationHacks.Fullbright.setKeybind(Integer.parseInt(var3[1]));
                        System.out.println("Setting Fullbright Keybind " + var3[1]);
                    }

                    if (var3[0].equals("Wallhack"))
                    {
                        Desteration.DesterationHacks.Wallhack.setKeybind(Integer.parseInt(var3[1]));
                        System.out.println("Setting Wallhack Keybind " + var3[1]);
                    }

                    if (var3[0].equals("Sprint"))
                    {
                        Desteration.DesterationHacks.Sprint.setKeybind(Integer.parseInt(var3[1]));
                        System.out.println("Setting Sprint Keybind " + var3[1]);
                    }

                    if (var3[0].equals("Forcefield"))
                    {
                        Desteration.DesterationHacks.Forcefield.setKeybind(Integer.parseInt(var3[1]));
                        System.out.println("Setting Forcefield Keybind " + var3[1]);
                    }
            } catch (Exception e) {
                System.err.println("Error Reading File: " + e);
                DesterationFileGenerator.editFile();
            }
        }
        System.out.println("Successfully read file.");
        System.out.println(Desteration.DesterationHacks.Gui.getKeybind());
        DesterationReader.close();
    } catch (IOException e) {
        System.err.println("Error Reading File: " + e);
    }
}

这是我的读取文件,这是我的枚举中的 setKeybind 和 getKeybind:

        public static void setKeybind(int i) {
        keyBind = i;
    }       
            public static int getKeybind() {
        return keyBind;
    }

如果我直接从readFile()它读取整数,它可以正常工作,但如果我从它读取它,getKeybind它会输出为零。

里面的Numbers文件都是不同的,例如: GUIKeybind是98。

这是我要求的完整枚举:

public static enum DesterationHacks {
    Gui,
    Xray,
    Fullbright,
    Wallhack,
    Sprint,
    Forcefield;

    private static boolean modState;
    private static int modMode;
    private static int keyBind;

    public static boolean getState() {
        return modState;
    }

    public static void setState(boolean flag){
        modState = flag;
    }

    public static void toggleState(){
        modState = !modState;
    }

    public static int getMode(){
        return modMode;
    }

    public static void setMode(int i){
        modMode = i;
    }

    public static int getKeybind() {
        return keyBind;
    }

    public static void setKeybind(int i) {
        keyBind = i;
    }
 }

}

4

1 回答 1

0

发现问题了,我傻了。枚举不应该是静态的,否则它们不会形成变化。谢谢你没有帮助。

于 2013-09-03T22:49:13.587 回答