Android Question Crashlytics reports crash Intnet not initialised

tsteward

Well-Known Member
Licensed User
Longtime User
I can rarely track down the errors Crashlytics reports to me. Hoping someone can help with this one.

b4xpagecar$ResumableSub_B4XPage_MenuClick.resume​

So I can see what page and what sub - no problem so far

then

Fatal Exception: java.lang.RuntimeException
Object should first be initialized (Intent).

You can't initialize and intent....can you?

My code where the intent happens
B4X:
Case B4XPages.MainPage.loc.Localize("Chrysler Security Gateway")
                            Dim url As String = "https://www.americankeysupply.com/pages/everything-you-need-to-know-about-the-chrysler-security-gateway?fbclid=IwAR3FouoT_qR5CHkbGW8f1kiWqbUAfphmFoPy22oVylc8A1VM3FdweJ9QVjY"
                            #IF b4a
                            Dim pIntent As PhoneIntents
                            StartActivity(pIntent.OpenBrowser(url))

Screen shots of the error page attached
 

Attachments

  • Screenshot 2025-02-03 191425.png
    Screenshot 2025-02-03 191425.png
    108.1 KB · Views: 84
  • Screenshot 2025-02-03 191614.png
    Screenshot 2025-02-03 191614.png
    156.6 KB · Views: 88

tsteward

Well-Known Member
Licensed User
Longtime User
Post the code in B4XPageCar.B4XPage_MenuClick.
B4X:
Private Sub B4XPage_MenuClick (Tag As String)
    #if b4a
    HideKeyboard
    #end if
    If viewingInfo = False Then
        Select Tag
            Case "additionalMenu"
                Dim l As List
                Dim rem As String = ""
                Dim addremote As Boolean = False
                l.Initialize
                ' get manufacturer notes
                Dim mrs As ResultSet = Main.sql1.ExecQuery2($"SELECT * FROM MakeGenInfo WHERE MakeID = ?"$, Array As String(Main.currentMakeID))
                Do While mrs.NextRow
                    l.Add("Tips - " & mrs.GetString("Title"))
                Loop
                mrs.Close
                'get manufacturer related remote procedured
                remoteProc.Clear
                Dim rsVehicles As ResultSet = Main.sql1.ExecQuery("SELECT * FROM Vehicles WHERE MakeID = " & Main.currentMakeID)
                Do While rsVehicles.NextRow
                    If rsVehicles.GetString("RemoteID") <> Null Then
                        rem = rsVehicles.GetString("RemoteID")
                        Do While rem.Contains("{%")
                            Dim newrem As String
                            newrem = rem.SubString2(rem.IndexOf("{%"),rem.IndexOf("%}")+2)
                            rem = rem.SubString(rem.IndexOf("%}")+2)
                            'add to list
                            If remoteProc.IndexOf(newrem) < 0 And newrem <> "{%21%}" And newrem <> "{%12%}" Then
                                addremote = True
                                Exit
                            End If
                        Loop
                    End If
                    If addremote Then Exit
                Loop
                'If B4XPages.MainPage.Pages.PageCarModel.infoList.Size > 0 Then
                If addremote Then
                    l.Add(Main.currentMake & " " & B4XPages.MainPage.loc.Localize("Remote Procedures"))
                End If
                l.Add(B4XPages.MainPage.loc.Localize("Transponder Conversion Guide"))
                Select Main.currentMake
                    Case "Toyota"
                        l.Add(B4XPages.MainPage.loc.Localize("Toyota Parts"))
                    Case "Ford"
                        l.Add(B4XPages.MainPage.loc.Localize("Ford Parts"))
                    Case "Chrysler"
                        l.Add(B4XPages.MainPage.loc.Localize("Chrysler Security Gateway"))
                        l.Add(B4XPages.MainPage.loc.Localize("Chrysler Immo Systems"))
                        l.Add(B4XPages.MainPage.loc.Localize("PIN Calculator"))
                End Select
                Select currentKeyway
                    Case "165"
                        l.Add("GM'Z' Keyway, Mystery")
                    Case "52"
                        l.Add("GM'Z' Keyway, Mystery")
                End Select
                #if b4a
                l.Add(B4XPages.MainPage.loc.Localize("Launch KeyDIY App"))
                l.Add(B4XPages.MainPage.loc.Localize("Launch XHorse App"))
                #end if
                Dim arr(l.Size) As String
                For i = 0 To l.Size - 1
                    arr(i) = l.Get(i)
                Next
            
                MenuOptions.Initialize
                MenuOptions.Options = arr
                MenuOptions.AllowMultiSelection = False
            
                wait for (dialog.ShowTemplate(MenuOptions,"","",B4XPages.MainPage.loc.Localize("CANCEL"))) complete (Result As Int)
                If Result = xui.DialogResponse_Positive Then
                    Select MenuOptions.SelectedItem
                        Case Main.currentMake & " " & B4XPages.MainPage.loc.Localize("Remote Procedures")
                            Dim rem As String
                            remoteProc.Clear
                            Dim tmpMake As Int
                            tmpMake = Main.currentMakeID
                            Dim rsVehicles As ResultSet = Main.sql1.ExecQuery("SELECT * FROM Vehicles WHERE MakeID = " & tmpMake)
                            Do While rsVehicles.NextRow
                                If rsVehicles.GetString("RemoteID") <> Null Then
                                    rem = rsVehicles.GetString("RemoteID")
                                    Do While rem.Contains("{%")
                                        Dim newrem As String
                                        newrem = rem.SubString2(rem.IndexOf("{%"),rem.IndexOf("%}")+2)
                                        rem = rem.SubString(rem.IndexOf("%}")+2)
                                        'add to list
                                        If remoteProc.IndexOf(newrem) < 0 And newrem <> "{%21%}" And newrem <> "{%12%}" Then
                                            remoteProc.Add(newrem)
                                        End If
                                    Loop
                                End If
                            Loop
                            If remoteProc.Size > 0 Then
                                Dim remdata As String
                                remdata = ""
                                For I = 0 To remoteProc.Size-1
                                    remdata = remdata & remoteProc.Get(I)
                                    remdata = remdata & "<br>"
                                Next
                                remdata = Routines.CreateRemotes(remdata)
                                remdata = Routines.CreateNotes(remdata)
                                WVCar.LoadHtml(Routines.addHTMLHeader("") & remdata & Routines.addHTMLFooter)
                                viewingInfo = True
                            Else
                                If viewingInfo Then
                                    viewingInfo = False
                                    AS_TabMenuAdvanced1.Index = B4XPages.MainPage.carCurrentTab
                                    AS_TabMenuAdvanced1.Refresh
                                End If
                            End If
                        Case B4XPages.MainPage.loc.Localize("Transponder Conversion Guide")
                            Dim temphtml As String
                            If File.Exists(File.DirAssets,"chips.html") Then                           
                                temphtml = File.ReadString(File.DirAssets,"chips.html")'FORMALLY GETTEXT
                                WVCar.LoadHtml(Routines.addHTMLHeader("") & temphtml)
                                viewingInfo = True
                                #if b4i
                                btnBack.mBase.Visible = True
                                #End If
                            End If
                        Case B4XPages.MainPage.loc.Localize("Toyota Parts")
                            WVCar.LoadUrl("https://www.toyodiy.com/parts/q.html")
                            viewingInfo = True
                        Case B4XPages.MainPage.loc.Localize("Ford Parts")
                            WVCar.LoadUrl("https://www.etis.ford.com/vehicleSelection.do")
                            viewingInfo = True
                        Case B4XPages.MainPage.loc.Localize("Chrysler Security Gateway")
                            Dim url As String = "https://www.americankeysupply.com/pages/everything-you-need-to-know-about-the-chrysler-security-gateway?fbclid=IwAR3FouoT_qR5CHkbGW8f1kiWqbUAfphmFoPy22oVylc8A1VM3FdweJ9QVjY"
                            #IF b4a
                            Dim pIntent As PhoneIntents
                            StartActivity(pIntent.OpenBrowser(url))
                            
                            #Else
                            If Main.App.CanOpenURL(url) Then Main.App.OpenURL(url)
                            #End If
                        Case B4XPages.MainPage.loc.Localize("Chrysler Immo Systems")
                            Dim rs As ResultSet = Main.sql1.ExecQuery2($"SELECT * FROM MakeGenInfo WHERE GenInfoID = ?"$, Array As String("8"))
                            Do While rs.NextRow
                                WVCar.LoadHtml(Routines.addHTMLHeader("") & rs.GetString("Data"))
                            Loop
                            rs.Close
                            viewingInfo = True
                        Case B4XPages.MainPage.loc.Localize("PIN Calculator")
                            B4XPages.ShowPage("Page HexCalc")
                        Case "GM'Z' Keyway, Mystery"
                            Dim url As String = "https://www.americankeysupply.com/pages/solving-the-gm-z-keyway-mystery-a-lishi-guide?fbclid=IwAR1A0lAUuG8adIRH0B5_uhtXkE8bsJbvbZD1nOg24TKaqlkr-iF5bnK7vWA"
                            #if b4a
                                Dim pIntent As PhoneIntents
                                StartActivity(pIntent.OpenBrowser(url))
                            #Else
                                If Main.App.CanOpenURL(url) Then Main.App.OpenURL(url)
                            #End If
                        
                            
                        Case B4XPages.MainPage.loc.Localize("Launch KeyDIY App")
                            #if B4a
                            Dim pac As PackageManager
                            StartActivity(pac.GetApplicationIntent("com.ecartek.en.kd"))
                            #End If
                            
                        Case B4XPages.MainPage.loc.Localize("Launch XHorse App")
                            #IF B4A
                                Dim pac As PackageManager
                                StartActivity(pac.GetApplicationIntent("com.xhorse.assembly"))
                            #End If
                            
                    End Select
                    If MenuOptions.SelectedItem.StartsWith("Tips") Then
                        mrs = Main.sql1.ExecQuery2($"SELECT * FROM MakeGenInfo WHERE Title = ?"$, Array As String(MenuOptions.SelectedItem.SubString(7)))
                        Do While mrs.NextRow
                            WVCar.LoadHtml(Routines.CreateNotes(mrs.GetString("Data")))
                        Loop
                        viewingInfo = True
                        mrs.Close
                    End If
                End If
            Case "printMenu"
                If note.StartsWith($"<p style="text-align: right;">(C) LARA App"$) = False Then
                    DateTime.DateFormat = "dd/MM/yyyy"
                    note = $"<p style="text-align: right;">(C) LARA App ${DateTime.Date(DateTime.Now)}</p><h1>${lblCarTitle.Text}</h1>"$ & note
                End If
                #IF B4A
                printer.PrintHtml("printCar",note)
                #Else
                'TODO
                #End If
                
            Case "timerMenu"
                #IF B4A
                SetAlarm("LARA")
                #Else
                'TODO
                #End If
                
        End Select
    End If
End Sub
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
BTW, posting the error messages as screenshot makes it difficult to read your post and help...

The problem is here:
B4X:
 Case B4XPages.MainPage.loc.Localize("Launch KeyDIY App")
                            #if B4a
                            Dim pac As PackageManager
                            StartActivity(pac.GetApplicationIntent("com.ecartek.en.kd"))
                            #End If
                            
                        Case B4XPages.MainPage.loc.Localize("Launch XHorse App")
                            #IF B4A
                                Dim pac As PackageManager
                                StartActivity(pac.GetApplicationIntent("com.xhorse.assembly"))
                            #End If

One of them returns an uninitialized intent. The target app is probably missing.
 
Upvote 0

tsteward

Well-Known Member
Licensed User
Longtime User
BTW, posting the error messages as screenshot makes it difficult to read your post and help...

The problem is here:
B4X:
 Case B4XPages.MainPage.loc.Localize("Launch KeyDIY App")
                            #if B4a
                            Dim pac As PackageManager
                            StartActivity(pac.GetApplicationIntent("com.ecartek.en.kd"))
                            #End If
                           
                        Case B4XPages.MainPage.loc.Localize("Launch XHorse App")
                            #IF B4A
                                Dim pac As PackageManager
                                StartActivity(pac.GetApplicationIntent("com.xhorse.assembly"))
                            #End If

One of them returns an uninitialized intent. The target app is probably missing.
Thank you for your help. Sorry about the screen shots, I'll try copy & paste in the future.

A> how did you narrow it down to that? just so I can learn.
B> how should I detect this and prevent the error?
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
A. These are the only places in the code, dealing with intents, that an uninitialized intent can occur. PhoneIntents will never return an invalid intent.
B.
B4X:
Private Sub StartAppIfAvailable (PackageName As String) As Boolean
 Dim pac As PackageManager
 Dim in As Intent = pac.GetApplicationIntent(PackageName)
 If in.IsInitialized Then StartActivity(in)
 Return in.IsInitialized
End Sub
 
Upvote 0
Top