wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Weird Error Message in Eclipse Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Weird Error Message in Eclipse" Watch "Weird Error Message in Eclipse" New topic
Author

Weird Error Message in Eclipse

marcus conway
Greenhorn

Joined: Oct 30, 2008
Posts: 12
Hello all,

This is my first post at the saloon. I've been writing a program that puts data from a .dat file into a table that I formatted. It's been going smoothly so far but recently I have been getting this error message and I don't know what it could be from.

Here are the two classes that are involved with it.




and here is the text in the data file (employee.dat)...



Any help would be greatly appreciated.

Thanks,

n
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36599
    
  16
Welcome to JavaRanch

Have you looked up NoSuchElementException and Scanner? Notice what it says about when a Scanner can throw a NoSuchElementException.

You need to alter the for loop. Get a pencil and paper and count how many times it repeats.

Probably not a good idea to use a for-loop which depends on counting lines. There are methods in the Scanner class which tell you whether you can read a next token. They will fit nicely into a while loop, then you can read a file of any size.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36599
    
  16
And the error message has nothing to do with Eclipse; it is from the Java Virtual Machine (JVM).
marcus conway
Greenhorn

Joined: Oct 30, 2008
Posts: 12
And would you look at that; I figured it out.

I deleted a line of the employee.dat file (making it so there's only 9 lines), and I had a loop that would run 10 times. So I just switched the line in my for loop from to .

I'm sure I'll be coming to the saloon more and more often.

Thanks
marcus conway
Greenhorn

Joined: Oct 30, 2008
Posts: 12
Originally posted by Campbell Ritchie:
Welcome to JavaRanch

Have you looked up NoSuchElementException and Scanner? Notice what it says about when a Scanner can throw a NoSuchElementException.

You need to alter the for loop. Get a pencil and paper and count how many times it repeats.

Probably not a good idea to use a for-loop which depends on counting lines. There are methods in the Scanner class which tell you whether you can read a next token. They will fit nicely into a while loop, then you can read a file of any size.



haha I just read your reply after I figured it out. Thanks for responding so soon.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36599
    
  16
You're welcome.

But try while (fileScan.hasNextLine()) . . .
It is much less error-prone than counting the lines.
marcus conway
Greenhorn

Joined: Oct 30, 2008
Posts: 12
Originally posted by Campbell Ritchie:
You're welcome.

But try while (fileScan.hasNextLine()) . . .
It is much less error-prone than counting the lines.


Yeah, I know what you mean. But the problem is that I'm going to have to be reading each String (first name, last name, and salary) one at a time and invoke various methods on each string. So i kind of need the line to be broken up; I don't know how to separate a whole line into three different ones .hasNextLine().
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36599
    
  16
Back to the Scanner API documentation, as in the link I posted yesterday!

I think the hasNextXXX() methods don't take any tokens from the input, so your next() should still work. But you will have to check the documentation.
I tend to have the opposite problem with Scanner; I find I need a "nextLine()" call every now and again to move onto the next line. But lots of experimentation and practice will soon get you up to speed.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Weird Error Message in Eclipse
 
Similar Threads
Hi, I need Help to convert String to Binary
Puzzled
Swaping Numbers
adding commas as thousands separators recursively
Truncating/ Padding a string