I assume this is a very simple problem but it's one I've ran into multiple times in the past couple months. I create a scanner within a method and then try to close it and it always gives me an error. This time the error is:
error: non-static method close() cannot be referenced from a static context Scanner.close();
public static void readArray(char[] arr){
String myMessage;
System.out.print("Input Message: ");
Scanner input = new Scanner(System.in);
myMessage = input.nextLine();// Read a line of message
for(int i = 0; i < myMessage.length(); i++){
arr[i] = myMessage.charAt(i);
}
Scanner.close();
}
Now I read that this is because I'm trying to call on the scanner class from within a method that is static? So scanner can't see the scanner class? If so, how should I properly handle things like this in the future? Should I import the scanner class within the method that creates it or is there something else that needs to be done?
Thanks