线程“main”中的异常 java.lang.Error: Unresolved compiler (PhraseOMatic)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12136345/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Exception in thread "main" java.lang.Error: Unresolved compilation (PhraseOMatic)
提问by OpMt
I tried to run the code from Head First Java as the following:
我尝试从 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);
}
}
and it is here that I receive this error:
正是在这里我收到了这个错误:
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
线程“main”中的异常 java.lang.Error:未解决的编译问题:
at PhraseOMatic.main(apples.java:2)
I see from the error that the problem is in line 2, but I can identify the error
我从错误中看到问题在第 2 行,但我可以识别错误
回答by adatapost
Have a look at exception trace (PhraseOMatic.main(apples.java:2)
). Your public class PhraseOMatic
must be saved with PhraseOMatic.java
file. Name of top-level
public class and .java file must be same.
查看异常跟踪 ( PhraseOMatic.main(apples.java:2)
)。您的公共课程PhraseOMatic
必须与PhraseOMatic.java
文件一起保存。top-level
公共类和 .java 文件的名称必须相同。
回答by christian.vogel
Just look at PhraseOMatic.main(apples.java:2)
. Your file is named apples.java
, but in Java your files HAVE to have the same name as your classes. In your case PhraseOMatic.java
.
看看吧PhraseOMatic.main(apples.java:2)
。您的文件名为apples.java
,但在 Java 中,您的文件必须与您的类同名。在你的情况下PhraseOMatic.java
。
回答by Mohammod Hossain
your stake trace:
您的权益追踪:
PhraseOMatic.main(apples.java:2)
So you are missing to run java to level class; your java main class is PhraseOMatic
所以你缺少运行 java 到 level 类;你的java主类是PhraseOMatic