Android Question Error adding second sheet to Excel workbook

bocker77

Active Member
Licensed User
Longtime User
When adding a second sheet to an Excel workbook I am getting this error.
java.lang.StringIndexOutOfBoundsException: length=0; index=0

Code is:
Dim wbkArmies As WritableWorkbook
Dim shtArmy1, shtArmy2 As WritableSheet
Dim strArmy1, strArmy2 As String
strArmy1 = "France"
strArmy2 = "Austria"
shtArmy1 = wbkArmies.AddSheet(strArmy1, 0)
shtArmy2 = wbkArmies.AddSheet(strArmy2, 1)

First AddSheet works but the second one gets the error. Does anyone know what I am doing wrong? I tried numerous things, such as adding data onto sheet 0 before adding the second, but get the same error.

Thanks for any help.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
1. Please use [code]code here...[/code] tags when posting code.
2. Always post the full error message from the logs.

I've tested it here and it works properly:
B4X:
Sub Activity_Create(FirstTime As Boolean)
   Dim wbkArmies As WritableWorkbook
   Dim shtArmy1, shtArmy2 As WritableSheet
   Dim strArmy1, strArmy2 As String
   strArmy1 = "France"
   strArmy2 = "Austria"
   wbkArmies.Initialize(File.DirRootExternal, "1.xls")
   shtArmy1 = wbkArmies.AddSheet(strArmy1, 0)
   shtArmy2 = wbkArmies.AddSheet(strArmy2, 1)
End Sub
 
Upvote 0

bocker77

Active Member
Licensed User
Longtime User
I am stupid. I found the problem. The strArmy2 string variable was never getting populated properly.
 
Upvote 0
Top