Android Question Error : NullPointerException

qey

Member
Hi everyone. I need help on this. It seem like theres a null value been passed in the programs. But im quite confused on how to solve it.

Error that ive got :

(NullPointerException) java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.String.equalsIgnoreCase(java.lang.String)' on a null object reference

This is the code for the error

B4X:
Sub convertBoolean(val As String) As Boolean
    Dim ok As Boolean = False
    Try {
        If val.EqualsIgnoreCase("1") Or val.EqualsIgnoreCase("true") Then
            ok = True       
        End If
    Catch
        Log(LastException)
    End Try
    Return ok
End Sub
Sub bool210(val As Boolean) As String
    Dim r As String = "0"
    Try {
        If val = True Then
            r="1"           
        End If
    Catch       
        Log(LastException)
    End Try
    Return r
End Sub
Sub convertNull(val As String) As String
    Try
        If val.EqualsIgnoreCase("null") Then
            val = ""   
        End If
    Catch
        val = ""
    End Try
    Return val
End Sub
Sub convertInt(val As String) As Int
    Dim i As Int = 0
    Try         
        i = val           
    Catch
        i = 0
    End Try
    Return i
End Sub
Sub IsNull(val As String, newVal As String) As String
    If val = Null Then
        val = newVal
    End If
    Return val
End Sub

Also this is the code where i found on Line 14 for GPSModule.Location the value is null

B4X:
Sub MapFragment1_Ready
    Sleep(500)
    Log("MapFragment1_Ready")
    Log(MapFragment1.GetOpenSourceLicenseInfo)
    
    gmap = MapFragment1.GetMap
    gmap.MapType = gmap.MAP_TYPE_NORMAL

    If  gmap.IsInitialized = False Then
        ToastMessageShow("Error initializing map.", True)
    End If
    
    Try
        If GPSModule.Location.EqualsIgnoreCase("") Then
            GetMapByAddress(JobMain.JobAddress)
            
            Dim m2 As Marker = gmap.AddMarker(GPSModule.latitude,GPSModule.longitude, "You Are Here")
            m2.Snippet = "Current Location"
        Else
            Log("get map failed")
        End If
    Catch
        Log("ERROR" & LastException.Message)
    End Try
End Sub

Sub Activity_Resume
    'MapFragment1.Initialize("Map", MapPanel)
End Sub

Sub Activity_Pause (UserClosed As Boolean)
    
End Sub

Sub GetMapByAddress (aDD As String)
    Dim gg As Geocoder   
    gg.Initialize("gg")   
    gg.GetFromLocationName(aDD,5,Null)     
End Sub

Sub gg_GeocodeDone(Results() As Location, Tag As Object)   
    xfs.WriteTextWriterDim("gg_GeocodeDone")
    If Results.Length > 0 Then
        Dim Location1 As Location
        Dim i As Int
    
        For i=0 To Results.Length-1
            Location1=Results(i)
            cpLat = Location1.Latitude
            cpLong = Location1.Longitude       
        Next
        Log("Try")
        Dim m1 As Marker = gmap.AddMarker(cpLat, cpLong, JobMain.JobAddress)
        m1.Snippet = Main.jobs.record.TransID
    Else
        ToastMessageShow("Location not found!", False)
    End If
    cp.Initialize(cpLat, cpLong, 15)
    gmap.AnimateCamera(cp)
End Sub

This is the code for GPSModule.Location in RegisterService

error3.PNG
 
Top