Italian [RISOLTO] Passare una view come parametro a una classe

Sabotto

Active Member
Licensed User
Voglio visualizzare il contenuto di un file di LOG in una label. Uso una classe a cui passo la Label e il file. Ma ricevo errore di mancata initizlize sulla Label passata.
Non si puo fare? Non si puo passare una View a un metodo di una classe?
ecco il semplice codice

B4X:
Sub Class_Globals
    
    Private Root As B4XView 'ignore
    Private xui As XUI 'ignore
    Private Label1 As Label
    Private oLog as clsLog   
    
End Sub

'You can add more parameters here.
Public Sub Initialize As Object
    Return Me
End Sub

Private Sub B4XPage_Created (Root1 As B4XView)
    
    Root = Root1
    Root.LoadLayout("lay_PagLog")
    oLog.MostraLog(Label1, xui.DefaultFolder, "Test LOG.log")

End Sub


'Nella classe clsLog
Sub MostraLog(aLabel As Label, mDir As String, FileName As String) 'ignore
    
    If File.Exists(mDir,NameFile) Then
        aLabel.Text= File.ReadString(mDir,NameFile)
    Else
        aLabel.Text= "Nessun file di LOG trovato" '===> RICEVO ERRORE QUI'
    End If
    
End Sub

Error occurred on line: 169 (clsLog)
java.lang.RuntimeException: Object should first be initialized (Label).
Did you forget to call Activity.LoadLayout?
at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:67)
at anywheresoftware.b4a.objects.TextViewWrapper.setText(TextViewWrapper.java:39)
at b4a.TestLineeTelec2.clslog._mostralog(clslog.java:435)
... ecc ecc
 

Sabotto

Active Member
Licensed User
Come non detto. Non so perchè, ma era rimasto il layout vecchio con il nome della label diverso.
 
Top