Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

java.util.Scanner refuses to take the next (or any) input (SOLVED)

"didn’t you forget the brackets? .nextLine() .next()" – experiment unit 1998X

"nextLine() is a function when calling function in java we need parenthesis after a function name to invoke a function. – bhawesh agrawal"

Current error message "cannot find symbol: variable nextLine in variable input of type Scanner"

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Eventually it is going to do much more than this but I don’t even understand why it won’t read…so it may take a bit XD

Method so far:

public static void flipCoins(Scanner input) 
{
    ArrayList<String> lines = new ArrayList<>();
    while(input.hasNextLine())
    {
        lines.add(input.nextLine);
        // WHERE THE ERROR OCCURS
    }
    System.out.print(lines.toString());
}

These are the links I have been trying to debug with:

whole Scanner class: https://www.tutorialspoint.com/java/util/java_util_scanner.htm

.next() specifically: https://www.tutorialspoint.com/java/util/scanner_next.htm

EDIT FOR MORE

I also receive this error: "cannot find symbol: variable next in variable input of type Scanner", with the following:

lines.add(input.next);

>Solution :

you are missing parenthesis"()", nextLine() is a function when calling function in java we need parenthesis after a function name to invoke a function. similar to what you did here

while(input.hasNextLine())

this will work

public static void flipCoins(Scanner input) 
{
    ArrayList<String> lines = new ArrayList<>();
    while(input.hasNextLine())
    {
        lines.add(input.nextLine());
    }
    System.out.print(lines.toString());
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading