0

For some reason the scanner seems to not be able to fine either nextLine() or next() and I don't know how to get it to work properly. If anyone could help this is the code so far

Class1

public static void main(String[] {
    usingStrings.testRun();
}

Class2

public static void testRun() {
    try {
    String input;
    System.out.println("Please enter your file name: ");
    input = scan.next();

    if (input.contains("e")) {
        System.out.println(true);
    } else {
        System.out.println(false);
    }

    if (input.contains(".jpg")) {
        System.out.println(true);
    } else {
        System.out.println(false);
    }

    if (input.contains("P")) {
        System.out.println(true); 
    } else {
        System.out.println(false);
    }
    scan.close();
    } catch (NoSuchElementException e) {
        System.err.println("No Such element exception");
    };
}

}

  • `scan.close();` also closes source of data for scanner. If it is `System.in` then you can no longer use it after it is closed. – Pshemo Mar 08 '18 at 21:05
  • Thanks! I read the other article and your right, my problem was closing the scanner. – Stew-coder95 Mar 15 '18 at 17:13

0 Answers0