1

我尝试从 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.Error 中的异常:未解决的编译问题:

at PhraseOMatic.main(apples.java:2)

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

4

3 回答 3

2

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

于 2012-08-27T04:51:58.817 回答
0

看看吧PhraseOMatic.main(apples.java:2)。您的文件名为apples.java,但在 Java 中,您的文件必须与您的类同名。在你的情况下PhraseOMatic.java

于 2012-08-27T04:54:31.887 回答
0

您的股份跟踪:

PhraseOMatic.main(apples.java:2)

所以你缺少运行 java 来调整类;你的 java 主类是 PhraseOmatic

于 2012-08-27T04:54:52.927 回答