This error has been a serious headache. it is very stubborn and no solution ever tried seems to work. Grok, Gemini, and other tried couldn't solve it either. All related problems found in the forum are not really related somehow as solution to theirs are not applicable to mine. Almost every AI are pointing toward same issue, but couldn't solve it or be specific enough. All their solutions and suggestions couldn't work.
The OCR based app is working fine, but when installed on a phone for first time, it crashes before showing first page and generate the crash logs below. However, if I ignored the error and pauses the app two or three times on same phone, everything works as normal henceforth without further crash. But I can't be telling users to pause app after crashing. Please help:
--------- beginning of main
~i:*** Service (starter) Create ***
~l1312189706:Using FileProvider? true
~l2380871502:moreapplist.db not found. download...
~i:*** Receiver (httputils2service) Receive (first time) ***
~i:** Service (starter) Start **
~i:** Activity (main) Create (first time) **
~l3923789571:*** mainpage: B4XPage_Created
~l4923789571:*** mainpage: B4XPage_Appear
~l5923789571:*** pmain21: B4XPage_Created [mainpage]
~l6923789571:*** mainpage: B4XPage_Disappear [mainpage]
~l7923789571:*** pmain21: B4XPage_Appear [mainpage]
~i:** Activity (main) Resume **
~e:java.lang.Exception: Sub complete signature does not match expected signature.
~e: at anywheresoftware.b4a.BA.raiseEvent2(BA.java:223)
~e: at anywheresoftware.b4a.BA$2.run(BA.java:395)
~e: at android.os.Handler.handleCallback(Handler.java:958)
~e: at android.os.Handler.dispatchMessage(Handler.java:99)
~e: at android.os.Looper.loopOnce(Looper.java:205)
~e: at android.os.Looper.loop(Looper.java:294)
~e: at android.app.ActivityThread.main(ActivityThread.java:8492)
~e: at java.lang.reflect.Method.invoke(Native Method)
~e: at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:640)
~e: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:982)
java.lang.Exception: Sub complete signature does not match expected signature.
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:223)
at anywheresoftware.b4a.BA$2.run(BA.java:395)
at android.os.Handler.handleCallback(Handler.java:958)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loopOnce(Looper.java:205)
at android.os.Looper.loop(Looper.java:294)
at android.app.ActivityThread.main(ActivityThread.java:8492)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:640)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:982)
Here is my starter code:
The OCR based app is working fine, but when installed on a phone for first time, it crashes before showing first page and generate the crash logs below. However, if I ignored the error and pauses the app two or three times on same phone, everything works as normal henceforth without further crash. But I can't be telling users to pause app after crashing. Please help:
--------- beginning of main
~i:*** Service (starter) Create ***
~l1312189706:Using FileProvider? true
~l2380871502:moreapplist.db not found. download...
~i:*** Receiver (httputils2service) Receive (first time) ***
~i:** Service (starter) Start **
~i:** Activity (main) Create (first time) **
~l3923789571:*** mainpage: B4XPage_Created
~l4923789571:*** mainpage: B4XPage_Appear
~l5923789571:*** pmain21: B4XPage_Created [mainpage]
~l6923789571:*** mainpage: B4XPage_Disappear [mainpage]
~l7923789571:*** pmain21: B4XPage_Appear [mainpage]
~i:** Activity (main) Resume **
~e:java.lang.Exception: Sub complete signature does not match expected signature.
~e: at anywheresoftware.b4a.BA.raiseEvent2(BA.java:223)
~e: at anywheresoftware.b4a.BA$2.run(BA.java:395)
~e: at android.os.Handler.handleCallback(Handler.java:958)
~e: at android.os.Handler.dispatchMessage(Handler.java:99)
~e: at android.os.Looper.loopOnce(Looper.java:205)
~e: at android.os.Looper.loop(Looper.java:294)
~e: at android.app.ActivityThread.main(ActivityThread.java:8492)
~e: at java.lang.reflect.Method.invoke(Native Method)
~e: at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:640)
~e: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:982)
java.lang.Exception: Sub complete signature does not match expected signature.
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:223)
at anywheresoftware.b4a.BA$2.run(BA.java:395)
at android.os.Handler.handleCallback(Handler.java:958)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loopOnce(Looper.java:205)
at android.os.Looper.loop(Looper.java:294)
at android.app.ActivityThread.main(ActivityThread.java:8492)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:640)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:982)
Here is my starter code:
Starter Code:
#Region Service Attributes
#StartAtBoot: False
#ExcludeFromLibrary: True
#End Region
Sub Process_Globals
Public rp As RuntimePermissions
Public sharedfolder As String
Private xui As XUI
Public provider As FileProvider
'program crash arrester
Private logs As StringBuilder
Private logcat As LogCat
Public const emailAddress As String = "..@gmail.com"
Public emailAddressbbb As String = "..@gmail.com" ' "MyEmail@aaa.com"
Public sql2 As SQL
Public id, typep,titlep, brandp, storep, descriptionp, downloadp, descriptionph,downloadph,rating,ratingh As String
Public dbsubfoldertest As String = "dbsub4test"
'for admob ads
Dim rewarded_item As Int = 0 'used in rewarded ad
Type AdSize (Native As Object, Width As Int, Height As Int) 'there are another option using AdsHelper class
Dim allowads As Boolean
' Dim adsenabledalbum As Boolean
Dim xui As XUI
' Public Timer2 As Timer 'for rewarded 1hr timer
Dim timer1starter As Timer
Dim const AD_FREE_DURATION As Long = DateTime.TicksPerMinute * 5 ' 1 hour
Dim const TIMER_INTERVAL As Long = 60000 ' 1 minute
Dim adFreeEndTime As Long
Dim currentAdFreeTime As Long
Dim activitynameglobal As String
'for inapp product payment
Public billing As BillingClient
Public const BILLING_KEY As String = "....." '
Public const ADS_SDK_IDinapp As String = "...."
Public const ADS_SDK_ID As String = "..."
Public AdsRemovedSubscription As Boolean 'purchase done or not boolean
Public AdsRemovedinapp As Boolean 'purchase done or not boolean
End Sub
Sub Service_Create
'This is the program entry point.
'This is a good place to load resources that are not specific to a single activity.
'....program crash arrester cont.....
logs.Initialize
#if RELEASE
logcat.LogCatStart(Array As String("-v","raw","*:F","B4A:v"), "logcat")
#end if
'.....................................
provider.Initialize
sharedfolder = rp.GetSafeDirDefaultExternal("shared")
timer1starter.Initialize("timer1starter", TIMER_INTERVAL)
LoadAdFreeEndTime
If adFreeEndTime > DateTime.Now Then
timer1starter.Enabled = True
End If
'....in app
billing.Initialize("billing")
If File.IsDirectory(xui.DefaultFolder, dbsubfoldertest) = False Then
File.MakeDir(xui.DefaultFolder, dbsubfoldertest)
End If
'.......'download moreapplist.db ...........' sql2.Initialize(xui.DefaultFolder, "moreapplist.db", False) 'DirInternal
If File.Exists(xui.DefaultFolder, "moreapplist.db") Then 'file exist, check that file against online
If File.IsDirectory(xui.DefaultFolder, dbsubfoldertest) = False Then
File.MakeDir(xui.DefaultFolder, dbsubfoldertest)
End If
' Wait For (DownloadAndSave(".....", xui.DefaultFolder & "/" & dbsubfoldertest, "moreapplist.db")) Complete (Successpp As Boolean)
'download online and check last modified
Wait For (DownloadAndSave("....", xui.DefaultFolder & "/" & dbsubfoldertest, "moreapplist.db")) Complete (Successpp As Boolean)
If Successpp Then
ToastMessageShow("Download succcessful", True)
'delete and redownload
Dim donline As Long
donline = File.LastModified(xui.DefaultFolder & "/" & dbsubfoldertest, "moreapplist.db")
Dim d As Long
d = File.LastModified(xui.DefaultFolder, "moreapplist.db")
If donline > d Then 'modified 'delete existing one in dirinternal and copy from sub folder
ToastMessageShow(DateTime.Date(d)&":"&DateTime.Date(donline), True)
' Before File.Delete and File.Copy
If sql2.IsInitialized Then sql2.Close
File.Delete(xui.DefaultFolder, "moreapplist.db")
Sleep(100)
File.Copy(xui.DefaultFolder & "/" & dbsubfoldertest, "moreapplist.db",xui.DefaultFolder, "moreapplist.db")
ToastMessageShow("Deleted and copied", True)
' ... then copy and re-initialize
sql2.Initialize(xui.DefaultFolder, "moreapplist.db", False)
Else
Log("No new moreapplist.db found. So, no download...")
End If
End If
Else
Log("moreapplist.db not found. download...")
'db does not exist at all first time, then download direct to dir internal
'link for moreapplist.db
Wait For (DownloadAndSave("...", xui.DefaultFolder, "moreapplist.db")) Complete (Success As Boolean) 'download direct to dirinternal not subfolder
If Success Then
ToastMessageShow("Download succcessful for first time", True)
Log("moreapplist.db downloaded...")
'i can go and unzip unde main2 later or do it here later
Else
ToastMessageShow("Failed to download",True)
End If
End If
If sql2.IsInitialized = False Then
sql2.Initialize(xui.DefaultFolder, "moreapplist.db", False) 'DirInternal
End If
sql2.Initialize(xui.DefaultFolder, "moreapplist.db", False) 'DirInternal
'sql1.ExecQuery("REINDEX messagesv")
'End If
Dim rs As ResultSet = sql2.ExecQuery("SELECT * FROM moreapptable")
Do While rs.NextRow
id = rs.GetString("AppID")
typep = rs.GetString("type")
titlep = rs.GetString("title")
brandp = rs.GetString("brand")
storep = rs.GetString("store")
descriptionp = rs.GetString("description")
descriptionph = rs.GetString("descriptionh")
downloadp = rs.GetString("download")
downloadph = rs.GetString("downloadh")
rating = rs.GetString("rating")
ratingh = rs.GetString("ratingh")
Loop
rs.close
End Sub
Sub Service_TaskRemoved
'This event will be raised when the user removes the app from the recent apps list.
End Sub
Sub Service_Destroy
End Sub
''SetServiceAttribute(Starter, android:foregroundServiceType, shortService)
'
'Add to starter service:
Private Sub Service_Timeout(Params As Map)
Service.StopForeground(51042) 'this is the id of the automatic foreground notification
End Sub
'
'Return true to allow the OS default exceptions handler to handle the uncaught exception.
Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
'wait for 500ms to allow the logs to be updated.
Dim jo As JavaObject
Dim l As Long = 500
jo.InitializeStatic("java.lang.Thread").RunMethod("sleep", Array(l))
logcat.LogCatStop
logs.Append(StackTrace)
Dim email As Email
email.To.Add(emailAddressbbb)
email.Subject = "Program crashed"
email.Body = logs
Log(logs)
'MsgboxAsync(
StartActivity(email.GetIntent)
ToastMessageShow("Hello worldkkp2", True)
Return True
End Sub
'
Sub Service_Start (StartingIntent As Intent)
Service.StopAutomaticForeground 'Starter service can start in the foreground state in some edge cases.
LoadAdFreeEndTime
If adFreeEndTime > DateTime.Now Then
timer1starter.Enabled = True
currentAdFreeTime = adFreeEndTime - DateTime.Now
ToastMessageShow($"Ad-free period remaining: ${DateTime.Time(currentAdFreeTime)}ms"$,True)
Else
If File.Exists(File.DirInternal, "adfreeendtime.txt") Then
File.Delete(File.DirInternal, "adfreeendtime.txt")
End If
End If
ToastMessageShow("Hello worldkkp1", True)
End Sub
'Sub Service_TaskRemoved
' 'This event will be raised when the user removes the app from the recent apps list.
'End Sub
'...................for Subscription....................
Sub billing_PurchasesUpdated (Result As BillingResult, Purchases As List)
'This event will be raised when the status of one or more of the purchases has changed.
'It will usually happen as a result of calling LaunchBillingFlow however it can be called in other cases as well.
If Result.IsSuccess Then
For Each p As Purchase In Purchases
If p.Sku = ADS_SDK_ID Then
HandleAdsPurchase(p)
Else
Log("Unexpected product...")
ToastMessageShow("Unexpected product...",True)
End If
Next
End If
End Sub
Private Sub HandleAdsPurchase (p As Purchase)
' If p.PurchaseState <> p.STATE_PURCHASED Then Return
If p.PurchaseState <> p.STATE_PURCHASED Then 'purchases are not successful, keep ads
AdsRemovedSubscription = False
B4XPages.MainPage.pmain2.adsenabledalbum = True
'use callsubdelay instead so that if menualbum activity is paused r in background, the code will still run
CallSubDelayed(B4XPages.MainPage,"restoreads")
Return
End If
'Verify the purchase signature.
'This cannot be done with the test id.
If p.Sku.StartsWith("barcode_sub") = False And billing.VerifyPurchase(p, BILLING_KEY) = False Then 'note: weekly_1 instead of ADS_SDK_ID
Log("Invalid purchase")
ToastMessageShow("Invalid purchase...",True)
Return
End If
If p.IsAcknowledged = False Then
'we either acknowledge the product or consume it.
Wait For (billing.AcknowledgePurchase(p.PurchaseToken, "")) Billing_AcknowledgeCompleted (Result As BillingResult)
Log("Acknowledged: " & Result.IsSuccess)
ToastMessageShow("Acknowledged: " & Result.IsSuccess,True)
End If
AdsRemovedSubscription = True
If AdsRemovedSubscription = True Then
'remove ads
' CallSubDelayed(Starter,"removeads")
' Activity_Create(True)
ToastMessageShow("Ads Subscription Removed...",True)
End If
'put my ads remover code here
Log("AdsRemovedSubscription")
' UpdateAdsState
CallSubDelayed(B4XPages.MainPage,"UpdateAdsState")
' CallSub(B4XPages.MainPage, "UpdateAdsState")
Return
End Sub
'...............for subscription billing ends....................
'...............for product billing....................
Sub billing_PurchasesUpdatedinapp (Result As BillingResult, Purchases As List)
'This event will be raised when the status of one or more of the purchases has changed.
'It will usually happen as a result of calling LaunchBillingFlow however it can be called in other cases as well.
If Result.IsSuccess Then
For Each p As Purchase In Purchases
If p.Sku = ADS_SDK_IDinapp Then
HandleAdsPurchaseinapp(p)
Else
Log("Unexpected product...")
ToastMessageShow("Unexpected product...",True)
End If
Next
End If
End Sub
Private Sub HandleAdsPurchaseinapp (p As Purchase)
' If p.PurchaseState <> p.STATE_PURCHASED Then Return
If p.PurchaseState <> p.STATE_PURCHASED Then 'purchases are not successful, keep ads
AdsRemovedSubscription = False
B4XPages.MainPage.pmain2.adsenabledalbum = True
'use callsubdelay instead so that if menualbum activity is paused r in background, the code will still run
CallSubDelayed(B4XPages.MainPage,"restoreads")
Return
End If
'Verify the purchase signature.
'This cannot be done with the test id.
If p.Sku.StartsWith("barcode_qrcode1") = False And billing.VerifyPurchase(p, BILLING_KEY) = False Then
Log("Invalid purchase")
ToastMessageShow("Invalid purchase ",True)
Return
End If
If p.IsAcknowledged = False Then
'we either acknowledge the product or consume it.
Wait For (billing.AcknowledgePurchase(p.PurchaseToken, "")) Billing_AcknowledgeCompleted (Result As BillingResult)
Log("Acknowledged: " & Result.IsSuccess)
ToastMessageShow("Acknowledged: " & Result.IsSuccess,True)
End If
AdsRemovedinapp = True
If AdsRemovedinapp = True Then
'remove ads
' CallSubDelayed(Starter,"removeads")
' Activity_Create(True)
ToastMessageShow("Ads Inapp Removed...",True)
End If
'put my ads remover code here
Log("AdsRemoved")
CallSubDelayed(B4XPages.MainPage,"UpdateAdsStateinapp")
' CallSub(B4XPages.MainPage, "UpdateAdsStateinapp")
Return
' UpdateAdsStateinapp
End Sub
'...............for product billing ends....................
'Sub Service_Destroy
'
'End Sub
Public Sub StartAdFree
LoadAdFreeEndTime
If adFreeEndTime > DateTime.Now Then
DateTime.TimeFormat = "HH:mm:ss"
' Add remaining time to new ad-free period
currentAdFreeTime = adFreeEndTime - DateTime.Now
adFreeEndTime = DateTime.Now + AD_FREE_DURATION + currentAdFreeTime
ToastMessageShow(currentAdFreeTime,True) ' & "mend:" & mEnd & "mstart:" & mStart
Else
adFreeEndTime = DateTime.Now + AD_FREE_DURATION
ToastMessageShow(adFreeEndTime,True) ' & "mend:" & mEnd & "mstart:" & mStart ConvertMillisecondsToString(
End If
SaveAdFreeEndTime(adFreeEndTime)
timer1starter.Enabled = True
End Sub
Sub SaveAdFreeEndTime(time As Long)
File.WriteString(File.DirInternal, "adfreeendtime.txt", time)
End Sub
Sub LoadAdFreeEndTime
If File.Exists(File.DirInternal, "adfreeendtime.txt") Then
adFreeEndTime = File.ReadString(File.DirInternal, "adfreeendtime.txt")
adFreeEndTime = adFreeEndTime
Else
adFreeEndTime = 0
End If
End Sub
Sub timer1starter_Tick
If adFreeEndTime > DateTime.Now Then
currentAdFreeTime = adFreeEndTime - DateTime.Now
ToastMessageShow("Ad-free period remaining:" & DateTime.Time(currentAdFreeTime) & "ms",True) 'ConvertMillisecondsToString(
Else
timer1starter.Enabled = False
File.Delete(File.DirInternal, "adfreeendtime.txt")
ToastMessageShow("Ad-free period has expired at:" & DateTime.Time(currentAdFreeTime) & "ms",True) 'ConvertMillisecondsToString(
Try
CallSubDelayed(Me,"Stop") ',"Your reward time is over"
Return
Catch
Log(LastException)
End Try
End If
End Sub
Sub Stop '(title As String)
Try
'restore ads once removed after one hour expires
B4XPages.MainPage.pmain2.adsenabledalbum = True
B4XPages.MainPage.pmain2.adsenabledalbum = B4XPages.MainPage.pmain2.adsenabledalbum.As(String).Replace(B4XPages.MainPage.pmain2.adsenabledalbum,True) 'B4XPages.MainPage.pmain2.adsenabledalbum
File.WriteString(xui.DefaultFolder,B4XPages.MainPage.ocrbasefolder&"/ads001.ini",B4XPages.MainPage.pmain2.adsenabledalbum)
ToastMessageShow("One hr exausted, you can go for more" & CRLF & DateTime.Time(adFreeEndTime) & "ms" & CRLF & DateTime.Time(DateTime.Now),True) 'ConvertMillisecondsToString(
Catch
Log(LastException)
End Try
End Sub
Sub removeads
Try
' CallSubDelayed(starter,"removeads")
B4XPages.MainPage.pmain2.adsenabledalbum = False
B4XPages.MainPage.pmain2.adsenabledalbum = B4XPages.MainPage.pmain2.adsenabledalbum.As(String).Replace(B4XPages.MainPage.pmain2.adsenabledalbum,False) 'B4XPages.MainPage.pmain2.adsenabledalbum
File.WriteString(xui.DefaultFolder,B4XPages.MainPage.ocrbasefolder&"/ads001.ini",B4XPages.MainPage.pmain2.adsenabledalbum)
ToastMessageShow("Ads removed successfully" ,True)
Return
Catch
Log(LastException)
End Try
End Sub
'........for more app cont.......
Sub DownloadAndSave (Url As String, Dir As String, FileName As String) As ResumableSub
Dim j As HttpJob
j.Initialize("", Me)
j.Download(Url)
Wait For (j) JobDone(j As HttpJob)
If j.Success Then
Dim out As OutputStream = File.OpenOutput(Dir, FileName, False)
File.Copy2(j.GetInputStream, out)
out.Close
End If
j.Release
Return j.Success
End Sub
Main Code:
#Region Project Attributes
#ApplicationLabel: All in One OCRs App
#VersionCode: 1
#VersionName: All in One OCRs App
'SupportedOrientations possible values: unspecified, landscape or portrait.'All-in-One OCRs
#SupportedOrientations: portrait
#CanInstallToExternalStorage: False
#End Region
#Region Activity Attributes
#FullScreen: False
#IncludeTitle: False
#End Region
'#BridgeLogger: True
'for other recognition not google based.....
#AdditionalRes: ..\resource
'...................
'for text recognition........
#AdditionalJar: com.google.android.gms:play-services-mlkit-document-scanner
#AdditionalJar: com.google.android.gms:play-services-mlkit-text-recognition
#AdditionalJar: kotlin-stdlib-1.6.10
#AdditionalJar: androidx.arch.core:core-runtime
'...............................
'for barcode recognition
#AdditionalJar: com.google.android.gms:play-services-code-scanner
#Multidex:True
Sub Process_Globals
Public ActionBarHomeClicked As Boolean
Public ActionMode, ContextMenu As JavaObject
Public Device As Phone
End Sub
Sub Globals
' Dim FocusedView As View
End Sub
Sub Activity_Create(FirstTime As Boolean)
Dim pm As B4XPagesManager
pm.Initialize(Activity)
If FirstTime Then
PDF417.initializepart1(Me)
End If
B4XPages.ShowPage("pmain21")
'' B4XPages.ShowPage("mainpage")
' B4XPages.ShowPage("plivescangB1")
End Sub
'Template version: B4A-1.01
#Region Delegates
Sub Activity_ActionBarHomeClick
ActionBarHomeClicked = True
B4XPages.Delegate.Activity_ActionBarHomeClick
ActionBarHomeClicked = False
End Sub
Sub Activity_KeyPress (KeyCode As Int) As Boolean
Return B4XPages.Delegate.Activity_KeyPress(KeyCode)
End Sub
Sub Activity_Resume
B4XPages.Delegate.Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
B4XPages.Delegate.Activity_Pause
End Sub
Sub Activity_PermissionResult (Permission As String, Result As Boolean)
B4XPages.Delegate.Activity_PermissionResult(Permission, Result)
End Sub
Sub Create_Menu (Menu As Object)
B4XPages.Delegate.Create_Menu(Menu)
End Sub
#if Java
public boolean _onCreateOptionsMenu(android.view.Menu menu) {
processBA.raiseEvent(null, "create_menu", menu);
return true;
}
#End If
#End Regionp