本文介绍了标记“;"、“{"的语法错误预期在此令牌之后的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
限时送ChatGPT账号..只是一个简单的类调用一个打印数组的类.我在 Eclipse 中遇到语法错误.我还收到一个错误,说我没有名为 Kremalation 的方法.
Just a simple class calls a class that prints an array. I get a syntax error in Eclipse. I also get an error that I don't have a method called Kremalation.
public class AytiMain {
public static void main(String[] args) {
AytiMain.Kremalation();
}
}
public class Kremalation {
String[] ena = { "PEINAW", "PEINOUSA", "PETHAINW" };
int i; // <= syntax error on token ";", { expected after this token
for (i = 0; i <= ena.lenght; i++)
System.out.println(ena[i]);
}
}
推荐答案
您在方法之外有代码(不是声明变量和/或初始化它),即:
You have code (which is not declaring a variable and/or initializing it) ouside a method, which is:
for (i=0; i<=ena.lenght; i++)
System.out.println(ena[i]);
在 Java 中,代码必须驻留在方法中.你不能调用一个类,你必须调用一个在内部声明的方法.
In Java, code MUST reside inside a method. You can't call a class, you have to call a method that is declared inside a class.
错误:
class ClassName {
for (...)
}
正确:
class ClassName {
static void method() {
for (...)
}
public static void main(String[] args) {
ClassName.method();
}
}
这篇关于标记“;"、“{"的语法错误预期在此令牌之后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论