Android Question Calling JavaObject from a Class

Mashiane

Expert
Licensed User
Longtime User
Hi

I have defined a class using JavaObject and it has inlive java code. In my activity I define and initialize the class then call a method from it. It gives an error. Is it possible to do this?

B4X:
'Class module
Sub Class_Globals
    Dim nativeMe As JavaObject
End Sub

'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize
    nativeMe.InitializeContext
End Sub

Sub getHexagonShape(bmp As Bitmap) As Bitmap
    Dim bm As Bitmap
    bm = nativeMe.RunMethod("getHexagonShape",Array(bmp))
    Return bm     
End Sub

In my Activity

B4X:
Private mImages As MashImages
mImages.Initialize

and then

B4X:
imgPerson.Bitmap = mImages.getHexagonShape(modMashiane.Getbitmap(face))

This last code fails with an error that says getBubbleBitmap method does not exist in my activity. Is there a way around to fixing this so that my class sees my activity?

Thanks.
 

cimperia

Active Member
Licensed User
Longtime User
This should solve your issue:
B4X:
Sub getHexagonShape(bmp AsBitmap) AsBitmap
  Dim bm AsBitmap
  nativeMe = Me
  bm = nativeMe.RunMethod("getHexagonShape",Array(bmp))
  Return bm
End Sub
 
Upvote 0
Top