File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Read Error: String index out of range: -1

 
Jay X Brown
Ranch Hand
Posts: 51
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all,
i am persistently getting the above-mentioned runtime error and at wit's end.
This code is designed to get parameters from a html form,
read data from two databases,
and output to an xml file.
Read Error: String index out of range: -1
For every 'customer' there are usually 3 addresses. It gets
stuck while reading the address table on the second itiration. I believe this is where this error is generated.
what am i doing wrong?
========*************====
[JUST WANTED TO TELL PEOPLE THAT I FIGURED IT OUT BY SLOW TRIAL AND ERROR. THE PROBLEM WAS SOME DATA MASSAGING WHERE I WAS TRYING TO TAKE OUT EXTRANEOUS DATA. MORE ON THAT IN THE JAVA GENERAL PAGE.]

=========
this is the code fragment where i think the error is occurring.

===================
the complete code is at:
http://y42.briefcase.yahoo.com/bc/jaybrown99/vwp2?.to k=bcMoy56A6cBKBmDZ&.dir=/Public&.dnm=custXMLwriter.java.java&.src=bc
===================

thanks, in advance, for your help.
jay

[This message has been edited by Jay Brown (edited March 26, 2001).]
[This message has been edited by Jay Brown (edited March 26, 2001).]
 
Frank Carver
Sheriff
Posts: 6920
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I believe the actual problem is where you say:

It is important to realize that ResultSet.next() increments the cursor as well as returning the status. So your first "if", actually steps past the first column.
A better solution might be:

As an aside, it is generally considered good practice to explicitly declare the fields you are retrieving from a query instead of using "select * from whatever". This helps make your code robust if you inadvertently change the ordering of the columns in the table, or add another column which is not used by this code. It also helps make your code more readable to reviewers, as we can see what should be in each column
I hope this helps.
 
Jay X Brown
Ranch Hand
Posts: 51
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for the response, Frank.
turns out (as i noted in my editted message) that the problem was elsewhere. but thanks for the tips.
i had totally forgotten that results.next increments the cursor. and i'll include the column names next time.
thanks again.
i love this board!!
jay
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic