0

I am trying to use my function to check if I have a certain value in a text file and I am having a issue with my code. My Boolean is not picking up the values that I declared in my while loop. My code is below.

public static Boolean isValueExistant(String value) throws FileNotFoundException {
    Scanner scanner = null;
    Boolean h = null;
    scanner = new Scanner(responses);
    while (scanner.hasNextLine()) {
        String lineFromFile = scanner.nextLine();
        if(lineFromFile.contains(value)) {
            h = true;
            break;
        } else {
            h = false;
            break;
        }
    }
    return h;
}

Calling function:

private static String askMessage() throws FileNotFoundException {
        if(FileUtils.isValueExistant("Value name = ")){
            String f5 = FileUtils.getValue("Value name = ");
            System.out.print(f5.replaceAll("Value name = ", "")+": ");
        }else if(!FileUtils.isValueExistant("Value name = ")){
            System.out.print("You: ");
        }
    String input = sc.nextLine();
    return input;
}

I just get a NullPointerException on my Boolean because it isn't changing from the null value to the true or false. Thanks in advance!

0 Answers0