Android Question Problem with "SetNinePatchButton"

D

Deleted member 103

Guest
Hi,

in Crashlytics always comes back this crash report:

The crash always happens at the procedure:
B4X:
Private Sub SetNinePatchButton(Btn As Button, DefaultImage As String, PressedImage As String)
    Dim r As Reflector
    Dim package As String
    Dim idDefault, idPressed As Int
    package = r.GetStaticField("anywheresoftware.b4a.BA", "packageName")
    idDefault = r.GetStaticField(package & ".R$drawable", DefaultImage)
    idPressed = r.GetStaticField(package & ".R$drawable", PressedImage)
    r.Target = r.GetContext
    r.Target = r.RunMethod("getResources")
    Dim sd As StateListDrawable
    sd.Initialize
    sd.AddState(sd.State_Pressed, r.RunMethod2("getDrawable", idPressed, "java.lang.int"))
    sd.AddCatchAllState( r.RunMethod2("getDrawable", idDefault, "java.lang.int"))
    Btn.Background = sd
End Sub

Of course all resources are available under ".. \ Objects \ res \ drawable".

As always, the crash does not happen with all devices, so it is difficult to make the mistake reproducible.
My question is now: can one change this procedure so that one no longer uses the library "Reflector"?
 
Last edited by a moderator:

agraham

Expert
Licensed User
Longtime User
This is a guess, but from the error it would seem to be related to the density of the display which would explain why it doesn't work on some devices. It looks like some density related resource is missing - but there my ignorance starts (and ends!) I'm afraid
 
Upvote 0
D

Deleted member 103

Guest
Thank you very much agraham.
I hope now that Erel knows something more, otherwise I have to think of something else.
 
Upvote 0
D

Deleted member 103

Guest
I guess that you aren't able to reproduce this error, right?
Yes, that's always the problem.

Is there anything special with the resource files? Maybe they are too large?
I do not think it's special, it's just these 2 files attached.
 

Attachments

  • btn_keyboard_key_normal.9.png
    715 bytes · Views: 237
  • btn_keyboard_key_pressed.9.png
    745 bytes · Views: 240
Upvote 0
D

Deleted member 103

Guest
I have now found another solution without having to use the function "SetNinePatchButton".
I think my keyboard looks even better now without bitmaps.

 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…