Java - <identifier>期望错误</identifier>

时间:2013-12-28 13:06:44

标签: java compiler-construction identifier

我正在编写一个java工具,在游戏模式处于活动状态时切换(具体来说,游戏是Dwarf Fortress,而mod是DFHack),程序即将完成。但是,我似乎无法获得正确的变量,告诉程序如何检查mod是否处于活动状态。 我得到了这个包含单个字符的状态文件,其中1表示活动,0表示不活动。 这是代码(顺便说一下,如果需要:我检查了文件的名称,它与类声明匹配)。

package nl.dirkkok.dfhacktoggle;

/* 
 * DFHacktoggle
 * 28-12-2013 @ 2:02 PM
 * 
 * This program will disable DFHack if it is enabled, and enable it if it is disabled.
 *
 * Using this tool is at your own risk. If you send me an email complaining about this program doing anything you dont want, then I will laugh at you, and tell you that you cant read. :)
 * 
 * Created by Dirk Kok <d.kok.2000@gmail.com>. This tool is my property, but I do not claim rights of neither Dwarf Fortress nor DFHack.
 */

import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.IOException;
import java.nio.file.NoSuchFileException;

public class Dfhacktoggle {
    private static Path statusfile = "dfhack-status";
    private boolean dfhack = false;
    private byte[] fileArray = new byte[1];
    private byte[] active = new byte[1];
    private byte[] inactive = new byte[1];
    private file dfhacksdl = "SDLdfhack.dll";
    private file vanillasdl = "SDLreal.dll";
    private file sdl = "SDL.dll";

    active[] <byte> = 1;
    inactive[] <byte> = 0;

    public static void main(String[] args) {
        try {
            fileArray = Files.readAllBytes(file);
            if (fileArray[0] == 1) {
                p("DFHack is active. Deactivating...");
                try {
                    if (vanillasdl.exists()) throw new java.io.IOException("File exists");
                    sdl.renameTo(dfhacksdl);
                    vanillasdl.renameTo(sdl);
                    Files.write(statusfile, inactive, WRITE);
                } catch (IOException x) {
                    errp("DFHack could not be deactivated. Reinstalling the program will solve this.");
                    errp("Detailed info:");
                    errp("IOException: " + x);
                } catch (NoSuchFileException x) {
                    errp("Status file could not be found. Reinstalling the program will solve this.");
                    errp("Detailed info:");
                    errp("NoSuchFileException: " + x);
                }
            } else if (fileArray[0] == 0) {
                p("DFHack is inactive. Activating...");
                try {
                    if(vanillasdl.exists()) throw new java.io.IOException("File exists");
                    sdl.renameTo(vanillasdl);
                    dfhacksdl.renameTo(sdl);
                    Files.write(statusfile, active, WRITE);
                } catch (IOException x) {
                    errp("Status could not be checked. Reinstalling the program will solve this.");
                    errp("Detailed info:");
                    errp("IOException: " + x);
                } catch (NoSuchFileException x) {
                    errp("Status file could not be found. Reinstalling the program will solve this.");
                    errp("Detailed info:");
                    errp("NoSuchFileException: " + x);
                }
            } else {
                errp("DFHack's status could not be checked. Reinstalling the program will solve this.");
            }
        } catch (IOException x) {
            errp("Status could not be checked. Reinstalling the program will solve this.");
            errp("Detailed info:");
            errp(x);
        }
    }

    public void p(String txt) {
        System.out.println(txt);
    }

    public void errp(String txt) {
        System.err.println(txt);
    }
}

编译器返回:

F:\Dfhack-swap>javac Dfhacktoggle.java

Dfhacktoggle:29: error: <identifier> expected
active[] <byte> = 1;
               ^

Dfhacktoggle:30: error: <identifier> expected
inactive[] <byte> = 0;
                 ^

1 个答案:

答案 0 :(得分:2)

您的语法错误,Java中没有active[] <byte> = 1;

如果要为其指定值,可以这样做

active[0] = 1;
inactive[0] = 0;

但是没有必要将数组用作布尔值,你可以将它定义为一个字节

byte active= 1;
byte inactive= 0;
相关问题