Skip to main content

Change in java.util.Scanner behavior

1 reply [Last post]
bburd
Offline
Joined: 2003-06-18

If I compile and execute the following program FROM THE WINDOWS COMMAND LINE, I get different behavior under Java 6 than I did under Java 5. (With Java 6, I get a NullPointerException; with Java 5, I didn't.)

import java.util.Scanner;

public class TestScan {

public static void main(String args[]) {
Scanner keyboard = new Scanner(System.in);

System.out.print("Number: ");
int i = keyboard.nextInt();
System.out.print("char: ");
char c = keyboard.findInLine(".").charAt(0);
}
}

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
timbell
Offline
Joined: 2003-06-10

You are correct. This behavior (NullPointerException) started in Mustang b45. I can't explain it, so I filed bug-id 6437114. The report should be visible in a few working days at this URL:

http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6437114

Thank you for the test case-

Tim

Message was edited by: timbell