Java 类、接口或枚举预期错误?
每次我编译的时候,它都会说这段代码有21个错误?我真的被困在这一点上。。。我什么都试过了。如果有人能帮助我,那就太好了 代码如下:Java 类、接口或枚举预期错误?,java,Java,每次我编译的时候,它都会说这段代码有21个错误?我真的被困在这一点上。。。我什么都试过了。如果有人能帮助我,那就太好了 代码如下: //Normal-Player End public static void archiveLogs(Player player, String[] cmd) { try { if (player.getRights() < 1) return; String location = "";
//Normal-Player End
public static void archiveLogs(Player player, String[] cmd) {
try {
if (player.getRights() < 1)
return;
String location = "";
if (player.getRights() >= 5) {
location = "data/logs/admin" + player.getUsername() + ".txt";
} else if (player.getRights() == 4) {
location = "data/logs/mod" + player.getUsername() + ".txt";
}
String afterCMD = "";
for (int i = 1; i < cmd.length; i++)
afterCMD += cmd[i] + ((i == cmd.length - 1) ? "" : " ");
BufferedWriter writer = new BufferedWriter(new FileWriter(location,
true));
writer.write("[" + now("dd MMMMM yyyy 'at' hh:mm:ss z") + "] - ::"
+ cmd[0] + " " + afterCMD);
writer.newLine();
writer.flush();
writer.close();
} catch (IOException e) {
e.printStackTrace();
}
}
public static String now(String dateFormat) {
Calendar cal = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat(dateFormat);
return sdf.format(cal.getTime());
}
private Commands() {
}
//正常播放结束
公共静态void archiveLogs(播放器,字符串[]cmd){
试一试{
if(player.getRights()<1)
返回;
字符串位置=”;
如果(player.getRights()>=5){
location=“data/logs/admin”+player.getUsername()+“.txt”;
}else if(player.getRights()==4){
location=“data/logs/mod”+player.getUsername()+“.txt”;
}
字符串afterCMD=“”;
for(int i=1;i
}
下面是我的编译器所说的:
writer.flush();
^
src\com\rs\game\player\content\Commands.java:2502: error: class, interface, or e
num expected
writer.close();
^
src\com\rs\game\player\content\Commands.java:2503: error: class, interface, or e
num expected
} catch (IOException e) {
^
src\com\rs\game\player\content\Commands.java:2505: error: class, interface, or e
num expected
}
^
src\com\rs\game\player\content\Commands.java:2515: error: class, interface, or e
num expected
public static String now(String dateFormat) {
^
src\com\rs\game\player\content\Commands.java:2517: error: class, interface, or e
num expected
SimpleDateFormat sdf = new SimpleDateFormat(dateFormat);
^
src\com\rs\game\player\content\Commands.java:2518: error: class, interface, or e
num expected
return sdf.format(cal.getTime());
^
src\com\rs\game\player\content\Commands.java:2519: error: class, interface, or e
num expected
}
^
Note: src\com\rs\game\player\Inventory.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
21 errors
compiling Dialogues
src\com\rs\game\player\content\Commands.java:2477: error: illegal start of type
return true;
^
src\com\rs\game\player\content\Commands.java:2477: error: ';' expected
return true;
^
src\com\rs\game\player\content\Commands.java:2483: error: class, interface, or e
num expected
public static void archiveLogs(Player player, String[] cmd) {
^
src\com\rs\game\player\content\Commands.java:2487: error: class, interface, or e
num expected
String location = "";
^
src\com\rs\game\player\content\Commands.java:2488: error: class, interface, or e
num expected
if (player.getRights() >= 5) {
^
src\com\rs\game\player\content\Commands.java:2490: error: class, interface, or e
num expected
} else if (player.getRights() == 4) {
^
src\com\rs\game\player\content\Commands.java:2492: error: class, interface, or e
num expected
}
^
src\com\rs\game\player\content\Commands.java:2494: error: class, interface, or e
num expected
for (int i = 1; i < cmd.length; i++)
^
src\com\rs\game\player\content\Commands.java:2494: error: class, interface, or e
num expected
for (int i = 1; i < cmd.length; i++)
^
src\com\rs\game\player\content\Commands.java:2494: error: class, interface, or e
num expected
for (int i = 1; i < cmd.length; i++)
^
src\com\rs\game\player\content\Commands.java:2496: error: class, interface, or e
num expected
BufferedWriter writer = new BufferedWriter(new FileWrite
r(location,
^
src\com\rs\game\player\content\Commands.java:2498: error: class, interface, or e
num expected
writer.write("[" + now("dd MMMMM yyyy 'at' hh:mm:ss z")
+ "] - ::"
^
src\com\rs\game\player\content\Commands.java:2500: error: class, interface, or e
num expected
writer.newLine();
^
src\com\rs\game\player\content\Commands.java:2501: error: class, interface, or e
num expected
writer.flush();
^
src\com\rs\game\player\content\Commands.java:2502: error: class, interface, or e
num expected
writer.close();
^
src\com\rs\game\player\content\Commands.java:2503: error: class, interface, or e
num expected
} catch (IOException e) {
^
src\com\rs\game\player\content\Commands.java:2505: error: class, interface, or e
num expected
}
^
src\com\rs\game\player\content\Commands.java:2515: error: class, interface, or e
num expected
public static String now(String dateFormat) {
^
src\com\rs\game\player\content\Commands.java:2517: error: class, interface, or e
num expected
SimpleDateFormat sdf = new SimpleDateFormat(dateFormat);
^
src\com\rs\game\player\content\Commands.java:2518: error: class, interface, or e
num expected
return sdf.format(cal.getTime());
^
src\com\rs\game\player\content\Commands.java:2519: error: class, interface, or e
num expected
}
^
Note: src\com\rs\game\player\Inventory.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
21 errors
compiled Main Server Folder
src\com\rs\game\player\content\Commands.java:2477: error: illegal start of type
return true;
^
src\com\rs\game\player\content\Commands.java:2477: error: ';' expected
return true;
^
src\com\rs\game\player\content\Commands.java:2483: error: class, interface, or e
num expected
public static void archiveLogs(Player player, String[] cmd) {
^
src\com\rs\game\player\content\Commands.java:2487: error: class, interface, or e
num expected
String location = "";
^
src\com\rs\game\player\content\Commands.java:2488: error: class, interface, or e
num expected
if (player.getRights() >= 5) {
^
src\com\rs\game\player\content\Commands.java:2490: error: class, interface, or e
num expected
} else if (player.getRights() == 4) {
^
src\com\rs\game\player\content\Commands.java:2492: error: class, interface, or e
num expected
}
^
src\com\rs\game\player\content\Commands.java:2494: error: class, interface, or e
num expected
for (int i = 1; i < cmd.length; i++)
^
src\com\rs\game\player\content\Commands.java:2494: error: class, interface, or e
num expected
for (int i = 1; i < cmd.length; i++)
^
src\com\rs\game\player\content\Commands.java:2494: error: class, interface, or e
num expected
for (int i = 1; i < cmd.length; i++)
^
src\com\rs\game\player\content\Commands.java:2496: error: class, interface, or e
num expected
BufferedWriter writer = new BufferedWriter(new FileWrite
r(location,
^
src\com\rs\game\player\content\Commands.java:2498: error: class, interface, or e
num expected
writer.write("[" + now("dd MMMMM yyyy 'at' hh:mm:ss z")
+ "] - ::"
^
src\com\rs\game\player\content\Commands.java:2500: error: class, interface, or e
num expected
writer.newLine();
^
src\com\rs\game\player\content\Commands.java:2501: error: class, interface, or e
num expected
writer.flush();
^
src\com\rs\game\player\content\Commands.java:2502: error: class, interface, or e
num expected
writer.close();
^
src\com\rs\game\player\content\Commands.java:2503: error: class, interface, or e
num expected
} catch (IOException e) {
^
src\com\rs\game\player\content\Commands.java:2505: error: class, interface, or e
num expected
}
^
src\com\rs\game\player\content\Commands.java:2515: error: class, interface, or e
num expected
public static String now(String dateFormat) {
^
src\com\rs\game\player\content\Commands.java:2517: error: class, interface, or e
num expected
SimpleDateFormat sdf = new SimpleDateFormat(dateFormat);
^
src\com\rs\game\player\content\Commands.java:2518: error: class, interface, or e
num expected
return sdf.format(cal.getTime());
^
src\com\rs\game\player\content\Commands.java:2519: error: class, interface, or e
num expected
}
^
21 errors
compiled Main Server Folder
src\com\rs\game\player\content\Commands.java:2477: error: illegal start of type
return true;
^
src\com\rs\game\player\content\Commands.java:2477: error: ';' expected
return true;
^
src\com\rs\game\player\content\Commands.java:2483: error: class, interface, or e
num expected
public static void archiveLogs(Player player, String[] cmd) {
^
src\com\rs\game\player\content\Commands.java:2487: error: class, interface, or e
num expected
String location = "";
^
src\com\rs\game\player\content\Commands.java:2488: error: class, interface, or e
num expected
if (player.getRights() >= 5) {
^
src\com\rs\game\player\content\Commands.java:2490: error: class, interface, or e
num expected
} else if (player.getRights() == 4) {
^
src\com\rs\game\player\content\Commands.java:2492: error: class, interface, or e
num expected
}
^
src\com\rs\game\player\content\Commands.java:2494: error: class, interface, or e
num expected
for (int i = 1; i < cmd.length; i++)
^
src\com\rs\game\player\content\Commands.java:2494: error: class, interface, or e
num expected
for (int i = 1; i < cmd.length; i++)
^
src\com\rs\game\player\content\Commands.java:2494: error: class, interface, or e
num expected
for (int i = 1; i < cmd.length; i++)
^
src\com\rs\game\player\content\Commands.java:2496: error: class, interface, or e
num expected
BufferedWriter writer = new BufferedWriter(new FileWrite
r(location,
^
src\com\rs\game\player\content\Commands.java:2498: error: class, interface, or e
num expected
writer.write("[" + now("dd MMMMM yyyy 'at' hh:mm:ss z")
+ "] - ::"
^
src\com\rs\game\player\content\Commands.java:2500: error: class, interface, or e
num expected
writer.newLine();
^
src\com\rs\game\player\content\Commands.java:2501: error: class, interface, or e
num expected
writer.flush();
^
src\com\rs\game\player\content\Commands.java:2502: error: class, interface, or e
num expected
writer.close();
^
src\com\rs\game\player\content\Commands.java:2503: error: class, interface, or e
num expected
} catch (IOException e) {
^
src\com\rs\game\player\content\Commands.java:2505: error: class, interface, or e
num expected
}
^
src\com\rs\game\player\content\Commands.java:2515: error: class, interface, or e
num expected
public static String now(String dateFormat) {
^
src\com\rs\game\player\content\Commands.java:2517: error: class, interface, or e
num expected
SimpleDateFormat sdf = new SimpleDateFormat(dateFormat);
^
src\com\rs\game\player\content\Commands.java:2518: error: class, interface, or e
num expected
return sdf.format(cal.getTime());
^
src\com\rs\game\player\content\Commands.java:2519: error: class, interface, or enum expected
}
^
Note: src\com\rs\game\player\Inventory.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
21 errors
Compiled all Successfully
Press any key to continue . . .
writer.flush();
^
src\com\rs\game\player\content\Commands.java:2502:error:class、interface或e
预期数量
writer.close();
^
src\com\rs\game\player\content\Commands.java:2503:error:class、interface或e
预期数量
}捕获(IOE异常){
^
src\com\rs\game\player\content\Commands.java:2505:error:class、interface或e
预期数量
}
^
src\com\rs\game\player\content\Commands.java:2515:error:class、interface或e
预期数量
现在使用公共静态字符串(字符串日期格式){
^
src\com\rs\game\player\content\Commands.java:2517:error:class、interface或e
预期数量
SimpleDataFormat sdf=新的SimpleDataFormat(日期格式);
^
src\com\rs\game\player\content\Commands.java:2518:error:class、interface或e
预期数量
返回sdf.format(cal.getTime());
^
src\com\rs\game\player\content\Commands.java:2519:error:class、interface或e
预期数量
}
^
注意:src\com\rs\game\player\Inventory.java使用未经检查或不安全的操作。
注意:使用-Xlint重新编译:未选中以获取详细信息。
21个错误
编辑对话
src\com\rs\game\player\content\Commands.java:2477:错误:类型的非法开始
返回true;
^
src\com\rs\game\player\content\Commands.java:2477:错误:';'预期
返回true;
^
src\com\rs\game\player\content\Commands.java:2483:error:class、interface或e
预期数量
公共静态void archiveLogs(播放器,字符串[]cmd){
^
src\com\rs\game\player\content\Commands.java:2487:error:class、interface或e
预期数量
字符串位置=”;
^
src\com\rs\game\player\content\Commands.java:2488:error:class、interface或e
预期数量
如果(player.getRights()>=5){
^
src\com\rs\game\player\content\Commands.java:2490:error:class、interface或e
预期数量
}else if(player.getRights()==4){
^
src\com\rs\game\player\content\Commands.java:2492:error:class、interface或e
预期数量
}
^
src\com\rs\game\player\content\Commands.java:2494:error:class、interface或e
预期数量
for(int i=1;i /**
* Even though this seems to be a static helper class,
* you still need the class declaration. The artefact
* name (Commands.java) won't suffice.
*/
public class Commands { // <--- Eh?
private Commands() {
// Prevent object from being instantiated
}
public static void archiveLogs(Player player, String[] cmd) {
// implementation omitted
}
public static String now(String dateFormat) {
// implementation omitted
}
}