Android Question Problem with "SetNinePatchButton"

D

Deleted member 103

Guest
Hi,

in Crashlytics always comes back this crash report:
Fatal Exception: android.content.res.Resources$NotFoundException: Resource ID #0x12e40030
at android.content.res.ResourcesImpl.getValueForDensity(ResourcesImpl.java:225)
at android.content.res.Resources.getDrawableForDensity(Resources.java:890)
at android.content.res.Resources.getDrawable(Resources.java:833)
at android.content.res.Resources.getDrawable(Resources.java:808)
at java.lang.reflect.Method.invoke(Method.java)
at anywheresoftware.b4a.agraham.reflection.Reflection.runmethod(Reflection.java:216)
at anywheresoftware.b4a.agraham.reflection.Reflection.RunMethod2(Reflection.java:817)
at fg.test1.clskeyboard._vvvvvvvvvvvvvvvvvvvvvvv5(clskeyboard.java:487)
at fg.test1.clskeyboard._vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv3(clskeyboard.java:380)
at fg.test1.clskeyboard._initialize(clskeyboard.java:345)
at fg.test1.main._activity_create(main.java:580)
at java.lang.reflect.Method.invoke(Method.java)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:196)
at fg.test1.main.afterFirstLayout(main.java:104)
at fg.test1.main.access$000(main.java:17)
at fg.test1.main$WaitForLayout.run(main.java:82)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6944)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)

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:

DonManfred

Expert
Licensed User
Longtime User
this is the english part of the forum. Please write english here.
 
Upvote 0

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
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 :(
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
    btn_keyboard_key_normal.9.png
    715 bytes · Views: 229
  • btn_keyboard_key_pressed.9.png
    btn_keyboard_key_pressed.9.png
    745 bytes · Views: 231
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. :)

upload_2019-4-14_16-26-6.png
 
Upvote 0
Top