Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Problem reading from file  RSS feed

 
Kari Nordmann
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Kari Nordmann
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try using the java.io.Scanner class instead of this "easyIO" thing; it's part of the official Java API and will work better.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!