Android Question java.lang.StringIndexOutOfBoundsException: length=0; index=1

giagia

Member
Licensed User
I have this problem : java.lang.Exception: java.lang.StringIndexOutOfBoundsException: length=0; index=1
when I write into my variable "Prezzo" type double .
F.Articoli(Codice).Prezzo1 is Double



B4X:
Sub Globals
Dim Prezzo As Double
End Sub

Private Sub aggiornaComanda(Codice As Int, Qta As Int)
        Log("aggiornaComanda: Codice=" & Codice & ", Qta=" & Qta)
    
    Try
        Dim i As Int, bAggiunto As Boolean=False
        
        Dim newIdComanda As Int = UtilityComanda.getMaxIndexComanda(F.Comanda)+1
        
    If F.UsaListini=0 Then
'    Log(GetType(F.ListinoCorrente))
    F.ListinoCorrente=1
    Else
        If F.ListinoCorrente <= 0 Then
            F.ListinoCorrente=F.ListinoBase
        End If
        If F.ListinoCorrente < 1 Or F.ListinoCorrente > 5 Then
            F.ListinoCorrente = 1
        End If
    End If
                
        Select Case F.ListinoCorrente
            Case 2
                Prezzo = F.Articoli(Codice).Prezzo2
            Case 3
                Prezzo = F.Articoli(Codice).Prezzo3
            Case 4
                Prezzo = F.Articoli(Codice).Prezzo4
            Case 5
                Prezzo = F.Articoli(Codice).Prezzo5
            Case Else
                Prezzo =F.Articoli(Codice).Prezzo1
        End Select
 

Star-Dust

Expert
Licensed User
Longtime User
It appears that F. Articles is empty and looks for item # 1 in an empty list.

Check the length with (if Array)
B4X:
log (F.Articoli.Length)
if Codice<F.Articoli.Length-1 then

Else
  ' fuori lista
End

Check the length with (if List)
B4X:
log (F.Articoli.Size)
if Codice<F.Articoli.Size-1 then

Else
  ' fuori lista
End
 
Last edited:
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
when I write into my variable "Prezzo" type double .
F.Articoli seems to be EMPTY but you are accessing Item 2 (Index 1) of it...
 
Upvote 0

giagia

Member
Licensed User
F.Articoli is not empty, it is length 10001
"Codice" is my index and it is <F.Articoli.length.
If I assign manually "Prezzo" to a random number I obtain the same error:eek:
 
Upvote 0
Top