Android Question java.lang.StringIndexOutOfBoundsException and stuck! <<SOLVED>>

Penfound

Active Member
Licensed User
Longtime User
Hi everyone. I've been stuck on this one for three days now and still can't figure out is going wrong.

I'm reading through a text file one line at a time, checking the contents of the line and then trying extract a piece of information from it using StringFunctions...

B4X:
Do While Line <> "0 TRLR"
   FinalText.Append("Record: ").Append(i).Append(CRLF)
   tmpLine = TextReader1.ReadLine
   Log(tmpLine) 'write the line to LogCat
   If tmpLine.contains("INDI") Then ' A person.
      NewRecord = True
      'parse out individual id
      tmpINDI(i) = sf.MidExtract(tmpLine,"@","@") 'crash happens here
      FinalText.Append("INDI: ").Append(tmpINDI(i)).Append(CRLF)
      'go and get record details
      Do While NewRecord

tmpLine, in this instance = "0 @I1@ INDI"

Is this a bug in stringfuncions or, more likely, something I've got wrong?

Any help would be most welcome
Thanks for looking
Penfound
 

Penfound

Active Member
Licensed User
Longtime User
Sorry I forgot to include the actual error


Error occurred on line: 231 (Gedcom)
java.lang.StringIndexOutOfBoundsException: length=0; regionStart=1; regionLength=-1
at java.lang.String.startEndAndLength(String.java:583)
at java.lang.String.substring(String.java:1464)
at adr.stringfunctions.stringfunctions._vvvv6(stringfunctions.java:479)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:697)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:336)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:246)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:134)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:157)
at anywheresoftware.b4a.debug.Debug.delegate(Debug.java:262)
at org.penfound.TreeBuilder.gedcom._readtextreader(gedcom.java:707)
at org.penfound.TreeBuilder.gedcom._button1_click(gedcom.java:693)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:697)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:339)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:246)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:134)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:157)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:153)
at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:78)
at android.view.View.performClick(View.java:4421)
at android.view.View$PerformClick.run(View.java:18190)
at android.os.Handler.handleCallback(Handler.java:725)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:175)
at android.app.ActivityThread.main(ActivityThread.java:5279)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
at dalvik.system.NativeStart.main(Native Method)
 
Upvote 0

Penfound

Active Member
Licensed User
Longtime User
Just discovered that an unlimited string array will only have 15 slots. Change the declaration from nothing to 500 and it worked perfectly!
 
Upvote 0
Top