我已經重新輸入LinkedIn學習材料Java fortune telling program.Radnom不能被解析爲一個類型 - 錯別字錯誤Java本身
很顯然,我沒有在隨機關鍵字錯字,但Java的顯示有關Radnom運行時錯誤。任何人都可以給我一個線索,可以導致這個錯誤?
錯誤:
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
Radnom cannot be resolved to a type
Type mismatch: cannot convert from String to ArrayList
Syntax error, insert "Finally" to complete TryStatement at customPrograms.FortuneTeller.main(FortuneTeller.java:15)
圖片證明:
我的代碼:
package customPrograms;
import java.util.Random;
import java.util.Scanner;
import java.util.ArrayList;
import java.io.*;
public class FortuneTeller {
public static void main(String[] args) {
File inputFile = new File("answers.txt");
ArrayList<String> answers = new ArrayList<String>();
String answer, response = "y";
Random rand = new Random();
System.out.println(rand);
try {
Scanner input = new Scanner(inputFile);
while(input.hasNextLine())
{
answer = input.nextLine();
answers.add(answer);
}
} catch(Exception e) {
System.out.println("The input file \"answers.txt\" was not found.");
System.out.println(e.toString());
}
Scanner in = new Scanner(System.in);
while (response.equalsIgnoreCase("y"))
{
System.out.println("The fortune teller is ready for you \n"
+ "Please think about question in your mind \n and hit enter for your reply");
}
in.nextLine();
System.out.println("The fortune teller says: \n" + answers.get(rand.nextInt(answers.size())) +
"\"\n");
System.out.println("Do you have another question? (y/n)");
response = in.nextLine();
}
}
'Radnom'是一個錯字嗎? – Berger
您是否複製並粘貼了該代碼或者是否重新輸入了該代碼?重新訓練往往會讓問題神祕地消失。 – molbdnilo
我認爲錯字只在Q ....的頭部或代碼不完整 –