This week's book giveaway is in the Artificial Intelligence forum.
We're giving away four copies of Pragmatic AI and have Noah Gift on-line!
See this thread for details.
Win a copy of Pragmatic AI this week in the Artificial Intelligence forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

error  RSS feed

 
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I'm getting this error:
java.lang.StringIndexOutOfBoundsException: String index out of
range: -1
What causes this error to occur? TIA.
Kevin
 
"The Hood"
Sheriff
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please show us the code that you were executing when you got this error. It LOOKS like you were doing a subString or messing with a character in the String and used an index past the length of the String.
 
kevin schmidt
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is the code:
String infoST = "";
BufferedReader inPDF = new BufferedReader(new FileReader(fName));
String info, allInfo = new String();
while((info = inPDF.readLine()) != null) {
allInfo += info;
}
String ends = allInfo.substring(allInfo.lastIndexOf("Rich"), allInfo.length());
inPDF.close();
StringTokenizer tempST = new StringTokenizer(ends, "/");
infoST = tempST.nextToken();

[This message has been edited by kevin schmidt (edited October 05, 2001).]
 
Ranch Hand
Posts: 3244
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kevin
Your problem is probably in the line:
String ends = allInfo.substring(allInfo.lastIndexOf("Rich"), allInfo.length());
The 'lastIndexOf("Rich")' is probably returning -1 (meaning there was no 'Rich' in the string. you should break it out of the substring call and test the return value, something like this would do it:

also, I assume that your catching the possible IOException from your readLine ?!?
Hope that helps

------------------
Dave
Sun Certified Programmer for the Java� 2 Platform
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!