| Author |
Problem reading from file
|
Kari Nordmann
Ranch Hand
Joined: Feb 12, 2007
Posts: 38
|
|
I'm learning to write and read from files, and now I'm gathering content from a .data file bit for bit. It worked fine at first, but now I get a weird result:
Leser fra fil HaiHus.data Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: -1 at java.lang.String.substring(Unknown Source) at easyIO.In.getCause(In.java:1325) at easyIO.In.inInt(In.java:986) at easyIO.InExp.inInt(InExp.java:942) at easyIO.In.inInt(In.java:945) at Hybelhus.<init>(Hybelhus.java:34)
This is the content of the file:
1 1 TOM HYBEL 0 2 1 TOM HYBEL 0 3 1 TOM HYBEL 0
What does the error mean? [ October 06, 2007: Message edited by: Kari Nordmann ]
|
 |
pete stein
Bartender
Joined: Feb 23, 2007
Posts: 1561
|
|
You might want to create and post a Short, Self Contained, Correct (Compilable), Example or SSCCE. This is a small application that you create that is compilable and runnable, and demonstrates your error, but contains no extraneous, unnecessary code that is not associated with your problem. This would allow us to play with your code and see your problem more directly. To see more about this and how to create this, please look at this link: SSCCE Also, where do you get your "easyIO" package? It's not part of standard java as far as I know. [ October 06, 2007: Message edited by: pete steinbear ]
|
 |
Ernest Friedman-Hill
author and iconoclast
Marshal
Joined: Jul 08, 2003
Posts: 24081
|
|
|
Basically just looks like a bug in "easyIO" -- again, whatever that is. You're calling "inInt()" and that method is throwing this exception -- perhaps because you're at the end-of-file.
|
[Jess in Action][AskingGoodQuestions]
|
 |
Kari Nordmann
Ranch Hand
Joined: Feb 12, 2007
Posts: 38
|
|
It does look like I'm at the end of the file... I tried using System.out.println to show me every value gathered, and the error occurs after all values have been gathered and I'm supposed to be at the end of the file. But "while (!innfil.endOfFile())" is supposed to make sure that doesn't happen... Still need to see an SSCCE?
|
 |
Ernest Friedman-Hill
author and iconoclast
Marshal
Joined: Jul 08, 2003
Posts: 24081
|
|
|
Try using the java.io.Scanner class instead of this "easyIO" thing; it's part of the official Java API and will work better.
|
 |
 |
|
|
subject: Problem reading from file
|
|
|