Andrej Buday Andrej Buday - 28 days ago 10
Java Question

Radnom cannot be resolved to a type - Typo error in Java itself

I have retyped LinkedIn learning material for Java fortune telling program.

Obviously I do not have typo in random keywords but Java shows runtime error about Radnom. Can anybody give me a clue what can cause this error?

Error:


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)


Image proof:

enter image description here

My Code:

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();
}
}

Answer

As long as 15th line is:

Random rand = new Random();

I think I figured out what is going on in your project: you don't have the .class files synced with .java sources.


SOLUTION

In Project menu:

select Build project option.

After mark Build Automatically to keep files synced.

enter image description here