Ok, I have this question that involves the Scanner class. Basically, when you want to perform garbage collection and there is a scanner object. You type scannerobject.close(); in your final clause.
My question is...if you make a scanner object in a public class method and then at the end you type object.close(), wHY does this affect the scanner in MAIN???? I haven't tried writing this in a try catch block, but I would think the results would be the same.
Anyways, I'm running a menu in a repitition statement in main. When the method is called, the method asks for user input, does some calculations and returns back to main, except when it gets to
Hey welcome back to my menu(menu displays options to perform various tasks)
type name = objectScanner.nextType(); ERROR
In this case it's a int and nextInt(). int name = object.nextInt();
Well, when I take out the scannerObject.close(); from my public class method, it works. There is something I am not understanding, I have searched the forums and checked many sites on google and I just want to know why I can't put the scanner.close() object in a public class method. <---even though the scanner object in main is different than the one in the public class method.
Exception in thread "main" java.util.NoSuchElementException
at java.util.Scanner.throwFor(Unknown Source)
at java.util.Scanner.next(Unknown Source)
at java.util.Scanner.nextInt(Unknown Source)
at java.util.Scanner.nextInt(Unknown Source)
at Driver.main(Driver.java:13)