Android Question I would like some help with a TYPE definition and arrays

Marc De Loose

Member
Licensed User
Longtime User
I have this as type def: in process globals
B4X:
Type iDashDispConfig2 (                    _
        ID                    As Int,            _
        MaxX                As Float,        _        ' for scaling to other devices
        MaxY                As Float,        _        ' for scaling to other devices
        labeldataInfo        As labelInfo,    _
        labellabelInfo        As labelInfo,    _
        rpmTopPos            As Float,        _
        Datas                As iRacingData,     _
        Graphs(2)            As iActorInfo    _        ' this holds the graphs (2 identicals possible possible)
        
    ' Some categories are not available in all actors
    Type iActorInfo (                         _
        ActorType            As String,        _ ' See Actor class name                    _
        thePosition         As B2Vec2,        _
        BaseName            As String,        _ ' According to Tiled json file
        inputMinVal            As Float,        _
        inputMaxVal            As Float,        _
        _ ' SPECIFIC TO Gauge
        _ ' SPECIFIC TO Rpmleds
        nrOfLeds            As Int,            _
        nrOfCenterLeds        As Int,            _
        ledgapX                As Float,        _
        _ ' to control data display
        bottomVal            As Float,        _     ' to hard fork if we want should be -1 if not in use
        middelVal            As Float,        _    '        "
        TopVal                As Float,        _    '        "
        _ ' to control visibility
        visible                As Boolean,        _
        USED                As Boolean        _
    )

   Dim Graphs(MAXIRACINGDATAS+1,2)            As iActorInfo

    )

I init the array
B4X:
        For i= 0 To MAXIRACINGDATAS-1
            For j =0 To 1
                Graphs(i,j).Initialize
            Next
        Next

then in a sub i try to do this:
B4X:
For i = 1 To MAXIRACINGDATAS
        Dim riDashDispConfig As iDashDispConfig2
                For j = 0 To 1
            Log("J in create = " & j)
            
            riDashDispConfig.Graphs(j)= Graphs(i,j)
        Next


next

And I am getting a java.lang.NullPointerException: Attempt to write to null array.

I know I am missing something.
The above stuff does more things but they are not the issue since without the for j loop all works fine.

Any help would be great
 

Marc De Loose

Member
Licensed User
Longtime User
I am an idiot.
the last code block should read:

B4X:
For i = 1 To MAXIRACINGDATAS
        Dim riDashDispConfig As iDashDispConfig2
        riDashDispConfig .Initialize
         For j = 0 To 1
            Log("J in create = " & j)
            
            riDashDispConfig.Graphs(j)= Graphs(i,j)
        Next


next

sorry to bother everyone... btw if you see I did something that should not be done let me know :)
 
Upvote 0
Top