[英]Could not find or load main class in java animal guessing game
I keep getting this error message 我不断收到此错误消息
Error: Could not find or load main class Animals.Animals Java Result: 1 错误:找不到或加载主类Animals.Animals Java结果:1
I don't think I did anything wrong to my program. 我认为我的程序没有做错任何事情。 I can't even find where I did something wrong. 我什至找不到我做错了什么。 Here's my program: 这是我的程序:
package Animals;
import java.util.*;
public class Animals {
private static final Scanner keyboard = new Scanner(System.in);
public static void introduction() {
System.out.println("WELCOME TO GUESS THE ANIMAL GAME");
System.out.println("If I am correct press Y and if I am wrong press N");
System.out.println("Ready? Let's begin!");
System.out.println("-------------------------------------------------");
}
public static void letsPlay(AnimalNode<String> latest) {
while (!latest.correct()) {
if (query(latest.getAnimal())) {
latest = latest.getleft();
} else {
latest = latest.getright();
}
}
System.out.println("Is it a " + latest.getAnimal());
if (!query("\nY or N?")) {
question(latest);
} else {
System.out.println("Winner!");
}
}
public static AnimalNode<String> AnimalTree() {
AnimalNode<String> root;
AnimalNode<String> child;
final String rootQuestion = "dog";
final String animal = "dog";
root = new AnimalNode<String>(rootQuestion, null, null);
return root;
}
public static void question(AnimalNode<String> latest) {
String setAnimal;
String correctAnimal;
String characteristic;
setAnimal = latest.getAnimal();
System.out.println("What is the correct answer? ");
correctAnimal = keyboard.nextLine();
System.out.println("What's a characteristic of " + correctAnimal
+ " that is different from " + setAnimal);
characteristic = keyboard.nextLine();
latest.setAnimal(characteristic);
System.out.println("A " + correctAnimal + characteristic);
if (query("Correct?")) {
latest.setLeft(new AnimalNode<String>(correctAnimal, null, null));
latest.setRight(new AnimalNode<String>(correctAnimal, null, null));
}
}
public static boolean query(String ask) {
String answer;
System.out.println(ask + "Y or N: ");
answer = keyboard.nextLine().toLowerCase();
while (!answer.startsWith("y") && !answer.startsWith("n")) {
System.out.println("Press the correct letter");
System.out.println("Let's try again");
}
return answer.startsWith("y");
}
public static void main(String[] args) {
AnimalNode<String> root;
introduction();
root = AnimalTree();
do {
letsPlay(root);
} while (query("-------------------------------------------------"
+ "\nPlay again?"));
}
}
The Animals
class MUST be in the Animals
directory... Animals
类必须在Animals
目录中...
\src
\Animals
Animals.java
It must have the package
decleation of package Animals
它必须具有package Animals
package
的package Animals
package Animals;
// imports
public class Animals {
//...
You can compile it from within the Animals
directory, but it would probably be safer to compile it in the parent directory... 您可以在Animals
目录中进行编译,但在父目录中进行编译可能会更安全...
javac -cp Animals Animals\*.java
You then need to use the fully qualified class name to run it (from the parent directly of Animals...) 然后,您需要使用完全限定的类名来运行它(直接从Animals的父类中...)
java Animals.Animals
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.