线程“main”中的异常java.lang.Error:未解析的编译(PhraseOMatic)

时间:2012-08-27 04:45:00

标签: 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", "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行,但我可以识别错误

3 个答案:

答案 0 :(得分:2)

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

答案 1 :(得分:0)

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

答案 2 :(得分:0)

您的赌注:

PhraseOMatic.main(apples.java:2)

所以你缺少运行java到level class;你的java主类是PhraseOMatic