Android Question New app version and new crash

D

Deleted member 103

Guest
Hi,
Yesterday I uploaded a new version of my app and new crashes have already been reported.
I've just tweaked a few things and fixed other bugs with the new Core.jar. I've compiled the app with "android.jar 25", maybe the bug is in this version?
Because the routine "initspeedpilot" and "mbbl._vvvvvvvvvvvvvvvvvvvvv6" have not changed.
crash_01.PNG
 

tigrot

Well-Known Member
Licensed User
Longtime User
CronoMilleMiglia? Millemiglia passes every spring end in front of my house... The strange is that it seems that other phones have already downloaded the new version and no issue was signaled. Are you trying to download an image from the network?
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
I've compiled the app with "android.jar 25", maybe the bug is in this version?
It doesn't matter which android.jar you use during compilation. It is most probably a bug in your code.

Because the routine "initspeedpilot" and "mbbl._vvvvvvvvvvvvvvvvvvvvv6" have not changed.
The new error message is better than in the previous version as now you can see where it fails. Previously it just showed something about CallSub.

Where is the code that initializes the canvas?
 
Upvote 0
D

Deleted member 103

Guest
Where is the code that initializes the canvas?
This is my code:

B4X:
Sub Activity_Create(FirstTime As Boolean)
...
    'Speedpilot initiallisieren
    CallSubDelayed(Me, "InitSpeedpilot")
...
End Sub

'The label "lblSettingSpeed" is initialized in the designer.
Private Sub InitSpeedpilot
    mBBL.SetTextSize(lblSettingSpeed, "000.00", 1, True)
End Sub


'Modul mBBL
'Der Parameter "Scale" bei Buttons nicht verwendet!
Sub SetTextSize(obj As View, txt As String, scale As Float, singleline As Boolean)
    Dim cv As Canvas

    'Log("SetTextSize: txt=" & txt & " :obj=" & obj)
    setSingleLine(obj, singleline)

    If obj Is Button Then
        Dim btn As Button = obj
        cv.Initialize(btn)
        SetButtonTextSize(btn, txt, cv)
    Else
        Dim lbl As Label = obj
        cv.Initialize(lbl)
        SetLabelTextSize(lbl, txt, scale, cv)
    End If
End Sub

'Sets the TextView to single line
Public Sub setSingleLine(TextView As View, SingleLine As Boolean)
    Dim jo = TextView As JavaObject
    jo.RunMethod("setSingleLine", Array As Object(SingleLine))
End Sub

Private Sub SetButtonTextSize(btn As Button, txt As String, cv As Canvas)
    Dim stu As StringUtils
    Dim dt As Float
    Dim h, Height As Int
    Dim w, Width As Int
    Height = btn.Height - 14dip
    Width = btn.Width
   
    btn.Text = txt
    btn.TextSize = 6
    dt = btn.TextSize
    h = stu.MeasureMultilineTextHeight(btn, txt)
    w = MeasureStringWidth(btn, dt, cv)
    Do While h <= Height
        dt = dt + 2
        btn.TextSize = dt
        h = stu.MeasureMultilineTextHeight(btn, txt)
        w = MeasureStringWidth(btn, dt, cv)
       
        If w >= (Width - 10dip) Or h > Height Then
            btn.TextSize = dt - 2
            Exit
        End If
    Loop
End Sub

Private Sub SetLabelTextSize(lbl As Label, txt As String, scale As Float, cv As Canvas)
    Dim stu As StringUtils
    Dim dt As Float
    Dim h, Height As Int
    Dim w, Width As Int
    Height = lbl.Height * scale
    Width = lbl.Width
   
    'WICHTIG! Die Width darf nicht weniger als null sein!
    If lbl.Width < 0 Then Return
   
    lbl.Text = txt
    lbl.TextSize = 6
    dt = lbl.TextSize
    h = stu.MeasureMultilineTextHeight(lbl, txt)
    w = MeasureStringWidth(lbl, dt, cv)
    Do While h <= Height
        dt = dt + 2
        lbl.TextSize = dt
        h = stu.MeasureMultilineTextHeight(lbl, txt)
        w = MeasureStringWidth(lbl, dt, cv)
       
        If w >= (Width - 10dip) Or h > Height Then
            lbl.TextSize = dt - 2
            Exit
        End If
    Loop
End Sub

Private Sub MeasureStringWidth(obj As View, TextSize As Float, cv As Canvas) As Float
    If obj Is Button Then
        Dim btn As Button = obj
        Return cv.MeasureStringWidth(btn.Text, btn.Typeface, TextSize)
    Else
        Dim lbl As Label = obj
        Return cv.MeasureStringWidth(lbl.Text, lbl.Typeface, TextSize)
    End If
End Sub
 
Upvote 0
D

Deleted member 103

Guest
CronoMilleMiglia? Millemiglia passes every spring end in front of my house... The strange is that it seems that other phones have already downloaded the new version and no issue was signaled. Are you trying to download an image from the network?
Then you know the people who use my app? :D

Are you trying to download an image from the network?
No, it has nothing to do with it.
 
Upvote 0
D

Deleted member 103

Guest
Here is my new classe, so the problem should be corrected, or you can still improve something?
B4X:
Sub Class_Globals
    Private bmp As Bitmap
    Private cvs As Canvas
End Sub

'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize
    bmp.InitializeMutable(1dip, 1dip)
    cvs.Initialize2(bmp)
End Sub

#Region TextSize vom Label, EditText und Button ändern

'Der Parameter "Scale" bei Buttons nicht verwendet!
Public Sub SetTextSize(obj As View, txt As String, scale As Float, singleline As Boolean)
    'Log("SetTextSize: txt=" & txt & " :obj=" & obj)
    setSingleLine(obj, singleline)

    If obj Is Button Then
        Dim btn As Button = obj
        SetButtonTextSize(btn, txt)
    Else
        Dim lbl As Label = obj
        SetLabelTextSize(lbl, txt, scale)
    End If
End Sub

'Sets the TextView to single line
Public Sub setSingleLine(TextView As View, SingleLine As Boolean)
    Dim jo = TextView As JavaObject
    jo.RunMethod("setSingleLine", Array As Object(SingleLine))
End Sub

Private Sub SetButtonTextSize(btn As Button, txt As String)
    Dim stu As StringUtils
    Dim dt As Float
    Dim h, Height As Int
    Dim w, Width As Int
    Height = btn.Height - 14dip
    Width = btn.Width
   
    btn.Text = txt
    btn.TextSize = 6
    dt = btn.TextSize
    h = stu.MeasureMultilineTextHeight(btn, txt)
    w = MeasureStringWidth(btn, dt)
    Do While h <= Height
        dt = dt + 2
        btn.TextSize = dt
        h = stu.MeasureMultilineTextHeight(btn, txt)
        w = MeasureStringWidth(btn, dt)
       
        If w >= (Width - 10dip) Or h > Height Then
            btn.TextSize = dt - 2
            Exit
        End If
    Loop
End Sub

Private Sub SetLabelTextSize(lbl As Label, txt As String, scale As Float)
    Dim stu As StringUtils
    Dim dt As Float
    Dim h, Height As Int
    Dim w, Width As Int
    Height = lbl.Height * scale
    Width = lbl.Width
   
    'WICHTIG! Die Width darf nicht weniger als null sein!
    If lbl.Width < 0 Then Return
   
    lbl.Text = txt
    lbl.TextSize = 6
    dt = lbl.TextSize
    h = stu.MeasureMultilineTextHeight(lbl, txt)
    w = MeasureStringWidth(lbl, dt)
    Do While h <= Height
        dt = dt + 2
        lbl.TextSize = dt
        h = stu.MeasureMultilineTextHeight(lbl, txt)
        w = MeasureStringWidth(lbl, dt)
       
        If w >= (Width - 10dip) Or h > Height Then
            lbl.TextSize = dt - 2
            Exit
        End If
    Loop
End Sub

Private Sub MeasureStringWidth(obj As View, TextSize As Float) As Float
    If obj Is Button Then
        Dim btn As Button = obj
        Return cvs.MeasureStringWidth(btn.Text, btn.Typeface, TextSize)
    Else
        Dim lbl As Label = obj
        Return cvs.MeasureStringWidth(lbl.Text, lbl.Typeface, TextSize)
    End If
End Sub

#End Region
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
1. There is a SingleLine property for both labels and buttons.
2. Buttons can be treated as labels. If the code that handles the buttons and labels is the same except of the type then you should remove the code for buttons and just treat both types as labels.
3. This hints to the cause of the original problem:
B4X:
'WICHTIG! Die Width darf nicht weniger als null sein!
If lbl.Width < 0 Then Return
If the label width was somehow negative then the call to Canvas.Initialize would have failed.
 
Upvote 0
D

Deleted member 103

Guest
What does my optimized classe now look like? :)
B4X:
Sub Class_Globals
    Private bmp As Bitmap
    Private cvs As Canvas

    Private stu As StringUtils
    Private dt As Float
    Private h, Height As Int
    Private w, Width As Int
End Sub

'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize
    bmp.InitializeMutable(1dip, 1dip)
    cvs.Initialize2(bmp)
End Sub

#Region TextSize vom Label, EditText und Button ändern

'Der Parameter "Scale" bei Buttons nicht verwendet!
Public Sub SetTextSize(obj As View, txt As String, scale As Float, singleline As Boolean)
    'Log("SetTextSize: txt=" & txt & " :obj=" & obj)
    setSingleLine(obj, singleline)

    If obj Is Button Then
        Dim btn As Button = obj
        Height = btn.Height - 14dip
        Width = btn.Width

        SetButtonTextSize(btn, txt)
    Else
        Dim lbl As Label = obj
        Height = lbl.Height * scale
        Width = lbl.Width
       
        SetLabelTextSize(lbl, txt, scale)
    End If
End Sub

'Sets the TextView to single line
Public Sub setSingleLine(TextView As View, SingleLine As Boolean)
    Dim jo = TextView As JavaObject
    jo.RunMethod("setSingleLine", Array As Object(SingleLine))
End Sub

Private Sub SetButtonTextSize(btn As Button, txt As String)   
    btn.Text = txt
    btn.TextSize = 6
    dt = btn.TextSize
    h = stu.MeasureMultilineTextHeight(btn, txt)
    w = cvs.MeasureStringWidth(btn.Text, btn.Typeface, dt)
    Do While h <= Height
        dt = dt + 2
        btn.TextSize = dt
        h = stu.MeasureMultilineTextHeight(btn, txt)
        w = cvs.MeasureStringWidth(btn.Text, btn.Typeface, dt)
       
        If w >= (Width - 10dip) Or h > Height Then
            btn.TextSize = dt - 2
            Exit
        End If
    Loop
End Sub

Private Sub SetLabelTextSize(lbl As Label, txt As String, scale As Float)   
    lbl.Text = txt
    lbl.TextSize = 6
    dt = lbl.TextSize
    h = stu.MeasureMultilineTextHeight(lbl, txt)
    w = cvs.MeasureStringWidth(lbl.Text, lbl.Typeface, dt)
    Do While h <= Height
        dt = dt + 2
        lbl.TextSize = dt
        h = stu.MeasureMultilineTextHeight(lbl, txt)
        w = cvs.MeasureStringWidth(lbl.Text, lbl.Typeface, dt)
       
        If w >= (Width - 10dip) Or h > Height Then
            lbl.TextSize = dt - 2
            Exit
        End If
    Loop
End Sub

#End Region
 
Upvote 0
D

Deleted member 103

Guest
New crash with new class.
So I do not know how to continue. :(
Yesterday tested on all my devices, no problem found.
Are my devices crash-safe?

crash_02.PNG
 
Upvote 0
Top