• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Problem reading from file

 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic