Android Question Reflector - how to run function from java library for B4A

ronovar

Active Member
Licensed User
Longtime User
How can i run method from B4A that is in library jar file?
I have B4AGallery that is fantastic library but i need to clear list items before inserting new one items. I found that i need to call this:

package:
it.giuseppe.salvi.library.photogallery.adapter
public class:
PhotoGalleryBaseAdapter
Function:
public void Clear()
{
itemsView.clear();
notifyDataSetChanged();
}

I try it this way but when running apk i get error.

B4X:
    Dim args1(1) As Object
    args1(0) = True 
    Dim r As Reflector  
    r.RunStaticMethod("it.giuseppe.salvi.library.photogallery.adapter.PhotoGalleryBaseAdapter" , "Clear" , args1, Null)

So i don't know how to call this public function in B4A using reflector.
 

walterf25

Expert
Licensed User
Longtime User
How can i run method from B4A that is in library jar file?
I have B4AGallery that is fantastic library but i need to clear list items before inserting new one items. I found that i need to call this:

package:
it.giuseppe.salvi.library.photogallery.adapter
public class:
PhotoGalleryBaseAdapter
Function:
public void Clear()
{
itemsView.clear();
notifyDataSetChanged();
}

I try it this way but when running apk i get error.

B4X:
    Dim args1(1) As Object
    args1(0) = True
    Dim r As Reflector 
    r.RunStaticMethod("it.giuseppe.salvi.library.photogallery.adapter.PhotoGalleryBaseAdapter" , "Clear" , args1, Null)

So i don't know how to call this public function in B4A using reflector.
What is the error you get, and also you need to set the target
B4X:
Dim r As Reflector
r .target = "your object"
 
Upvote 0

ronovar

Active Member
Licensed User
Longtime User
Ok...i try this but it give me error when run:

B4X:
Sub Globals
    Dim Gallery As PhotoGallery
    Dim r As Reflector
End Sub

Sub Activity_Create(FirstTime As Boolean)

    'INIT Gallery
    Gallery.Initialize("Gallery")

    
'TYPE Gallery
    Gallery.TextSize = 16
    Gallery.TextColor = Colors.Yellow
    Gallery.ShowText = False
    Gallery.ItemWidth = 296
    Gallery.ItemHeight = 436
    Gallery.Spacing = 50
   
    Gallery.ScaleType = Gallery.ScaleType.Center_Crop
    Gallery.SetNoEffect = False
    Gallery.SetBorderColor=Colors.Yellow
    Gallery.SetCornerRadius = 10
    Gallery.SetBorderWidth = 2
    Gallery.SetOval = False

    'TARGET IS GALLERY --> PHOTOGALLERY
    r.Target = Gallery
    r.Target = r.RunMethod2("it.giuseppe.salvi.library.photogallery.adapter", "Clear", "it.giuseppe.salvi.library.photogallery.adapter.PhotoGalleryBaseAdapter")

And here is picture of received error when apk is run...i think i wrong declared runmethod2
 

Attachments

  • Untitled.jpg
    Untitled.jpg
    25.9 KB · Views: 272
Upvote 0

walterf25

Expert
Licensed User
Longtime User
B4X:
dim r as Reflector
r.Target = gallery

r.RunMethod("Clear")
Ok...i try this but it give me error when run:

B4X:
Sub Globals
    Dim Gallery As PhotoGallery
    Dim r As Reflector
End Sub

Sub Activity_Create(FirstTime As Boolean)

    'INIT Gallery
    Gallery.Initialize("Gallery")

   
'TYPE Gallery
    Gallery.TextSize = 16
    Gallery.TextColor = Colors.Yellow
    Gallery.ShowText = False
    Gallery.ItemWidth = 296
    Gallery.ItemHeight = 436
    Gallery.Spacing = 50
  
    Gallery.ScaleType = Gallery.ScaleType.Center_Crop
    Gallery.SetNoEffect = False
    Gallery.SetBorderColor=Colors.Yellow
    Gallery.SetCornerRadius = 10
    Gallery.SetBorderWidth = 2
    Gallery.SetOval = False

    'TARGET IS GALLERY --> PHOTOGALLERY
    r.Target = Gallery
    r.Target = r.RunMethod2("it.giuseppe.salvi.library.photogallery.adapter", "Clear", "it.giuseppe.salvi.library.photogallery.adapter.PhotoGalleryBaseAdapter")

And here is picture of received error when apk is run...i think i wrong declared runmethod2
first change this

B4X:
r.Target = Gallery
    r.Target = r.RunMethod2("it.giuseppe.salvi.library.photogallery.adapter", "Clear", "it.giuseppe.salvi.library.photogallery.adapter.PhotoGalleryBaseAdapter")

to this

B4X:
r.Target = Gallery
r.RunMethod2("it.giuseppe.salvi.library.photogallery.adapter", "Clear", "it.giuseppe.salvi.library.photogallery.adapter.PhotoGalleryBaseAdapter")

and lastly why don't you just try this.

B4X:
dim r as Reflector
r.Target = gallery

r.RunMethod("Clear")
 
Upvote 0

ronovar

Active Member
Licensed User
Longtime User
I try it but i im getting same error...NoSuchMethodException...so here i created emtpy project...You just need to download and enable B4AGalleryView and Reflection library. And run code...so that You can view what is error coming.
 

Attachments

  • example.zip
    6.3 KB · Views: 375
Upvote 0
Top