Java Help Please

  • Thread starter Thread starter Garee
  • Start date Start date

Garee

Garee

I am working on one of my university Java course assessments and I keep experiencing this error.

Code:
Exception in thread "main" java.util.InputMismatchException
	at java.util.Scanner.throwFor(Unknown Source)
	at java.util.Scanner.next(Unknown Source)
	at java.util.Scanner.next(Unknown Source)
	at Person.<init>(Person.java:49)
	at ProcessMembers.main(ProcessMembers.java:22)

This occurs in my Person class constructor.

Code:
	public Person( Scanner inputScanner )
	{
		this.lastName = inputScanner.next();
		this.firstName = inputScanner.next(",");
		this.male = Gender( inputScanner.next(",") );
		this.dateOfBirth = new Date( inputScanner.nextInt(), inputScanner.nextInt(), inputScanner.nextInt() ); 
	}

The Scanner in this case is reading from a text file containing details of some people in the format:

Code:
Adams Bill, M, 16 03 63

The problem seems to be the delimiter "," as the code compiles correctly when I only use .next()


Any help is much appreciated, thanks.
 
Someone correct me if I'm wrong, but wouldn't you need to change delimiter by using inputScanner.useDelimiter(", ");? Obviously, you'd then have to change it back once you were done using that specific delimiter.

I think you may be right. I mis-read the API and thought it was similiar to the way .split(",") is used.
 
Back
Top Bottom