“线程中的异常”;“主要”;java.lang.Error:未解析编译(短语语法)

“线程中的异常”;“主要”;java.lang.Error:未解析编译(短语语法),java,Java,我尝试从Head First Java运行代码,如下所示: public class PhraseOMatic { public static void main(String[] args){ String[] wordListOne = {"24/7", "mult-iTier", "30,000 foot", "B-to-B", "win-win", "front-end", "web-based", "pervasive", "smart", "six-sigma", "

我尝试从Head First Java运行代码,如下所示:

public class PhraseOMatic {
   public static void main(String[] args){

    String[] wordListOne = {"24/7", "mult-iTier", "30,000 foot", "B-to-B", "win-win", "front-end", "web-based", "pervasive", "smart", "six-sigma", "critical-path", "dynamic"};

    String[] wordListTwo = {"empowered", "sticky", "value-added", "oriented", "centric", "distributed", "clustered", "branded", "outside-the-box", "positioned", "networked", "focused", "leveraged", "aligned", "targeted", "shared", "cooperative", "accelerated"};

    String[] wordListThree = {"process", "tipping-point", "solution", "architecture", "cor competency", "strategy", "mindshare", "portal", "space", "vision", "paradigm", "mission"};

    int oneLength = wordListOne.length;
    int twoLength = wordListTwo.length;
    int threeLength = wordListThree.length;

    int rand1 = (int) (Math.random() * oneLength);
    int rand2 = (int) (Math.random() * twoLength);
    int rand3 = (int) (Math.random() * twoLength);

    String phrase = wordListOne[rand1] + " " + wordListTwo[rand2] + " " + wordListThree[rand3];

    System.out.println("What we need is a " + phrase);
    }
}
我就是在这里收到这个错误:

线程“main”java.lang中出现异常。错误:未解决的编译问题:

at PhraseOMatic.main(apples.java:2)

我从错误中看出问题在第2行,但我可以识别错误

请查看异常跟踪(
PhraseOMatic.main(apples.java:2)
)。您的公共类
PhraseOMatic
必须与
PhraseOMatic.java
文件一起保存。顶级公共类和.java文件的名称必须相同。

只需查看
PhraseOMatic.main(apples.java:2)
。您的文件名为
apples.java
,但在java中,您的文件必须与类同名。在您的案例中
PhraseOMatic.java

您的股份跟踪:

PhraseOMatic.main(apples.java:2)

因此,您无法运行java来升级类;您的java主类是PhraseOMatic

i编译并运行程序没有错误发生请将代码与
package
语句一起发布,以便我们可以帮助您。@AVD这似乎是OP的所有代码。无论如何,OP提供了足够的信息来解决这个问题:类PhraseOMatic保存在一个名为“apples.java”的文件中。我认为存在一个IDE,可能是OP删除了包语句或其他东西。请将.java文件重命名为
PhraseOMatic.java
。你有IDE(netbeans/eclipse等)吗?