Skip to Main Content

Java APIs

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

java.lang.StringIndexOutOfBoundsException-urgent plz.

843810May 16 2006 — edited Oct 25 2010
import java.io.*;
import java.lang.String.*;
import java.util.*;

public class ReadFile {

//--------------------------------------------------< main >--------//

public static void main (String[] args) {
ReadFile t = new ReadFile();
t.readMyFile();
}
//--------------------------------------------< readMyFile >--------//
void readMyFile() {

String line = null;
String dcn = null;
String pfn = null;
String pln = null;
String pdob = null;
String ssd = null;

try {

FileReader fr = new FileReader("C:\\ClaimsData\\ClaimsExtract.txt");
BufferedReader br = new BufferedReader(fr);

line = new String();
while ((line = br.readLine()) != null) {
//A00002314376A5272201102300000000MASARU OKUDA 1933012520050722B101 20051001
//Each line of ClaimsExtract.txt is exactly in above form
// and there are about 1000 such lines

dcn = line.substring(13,24);
pfn = line.substring(32,42);
pln = line.substring(42,57);
pdob = line.substring(57,65);
ssd = line.substring(65,73);
//System.out.println(dcn+" "+pfn+" "+pln+" "+pdob+" "+ssd);

}
fr.close();
} catch (IOException e) {
// catch possible io errors from readLine()
System.out.println("Uh oh, got an IOException error!");
e.printStackTrace();
}

} // end of readMyFile()

} // end of class


When I execute this class, I get the following error just before the last two lines are displayed. Can anyone please tell me a workaround for this ???
java.lang.StringIndexOutOfBoundsException: String index out of range: 24
at java.lang.String.substring(String.java:1441)
at ReadFile.readMyFile(ReadFile.java:34)
at ReadFile.main(ReadFile.java:11)

52650143086 LESCIA SHEVER 19581113 20030618
52668163008 RANDAL IWAMATO 19700803 20050618
Exception in thread "main"

Comments

843834
Your idea is interesting. But then, XML is an SGML derivative that follows standards laid down by its parent. I guess what you are suggesting is another standard.

I do not completely agree with ur point that XML start & end tags duplicate information. Rather it improves readability of the document.

Its always better to say bValidationRequired than bValReq, the intrepretations could vary on the latter.


Just my thoughts.
843834
Hi Sanjaya,
in ur case there are only 2 elements. when there are lot of elements in ur xml file, not ending with the closed tag with the element name will lead to a confusion & especially when u start writing transformations it would be more tedious.
cheers
anand
843834
Hi All:

I think you missed a point!! Why do I want readability. I think I am not going to write Email in XML:-):-). It is data exchange mode between programs. I think in that case I will have to say: TCP/IP is not readable :-).

AT least for those cases, where programs talk to each other, you DO NOT need human readability.

Nice to hear all your ideas. So nice....

-Sanjay
843834
Hey Sanjay,

Well you mentioned that readability in XML scores low when it is used for exchanging data. I am pretty sure that XML is NOT only intended for data exchange. It is useful in other situations too. Think of XML Content Mgmt (just to say). You definitely need readability here, thou the actual content may be published in a totally diff way.

XML's main purpose is to have custom document structure. It is data/Content driven. Anything that is data centric, MUST be readable too. Why do you have custom document structure is another question and ur point (data exchange) comes into picture as well :-).

Do you agree now?

Srini.
1 - 4
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Nov 22 2010
Added on May 16 2006
10 comments
1,468 views