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
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,469 views