Android Question Inline Java. Why does this code fail both with word 'static' and without 'static'?

hatzisn

Expert
Licensed User
Longtime User
Good morning everyone,

I remembered this code from @Mashiane who pressed a like on it. I am trying to create now a b4xlib to get google primary account, that will be used only in B4A. The code fails and it fails both with adding the word "static" in the inline JAVA functions and without adding it. Why is this happening? The project is attached...

Thanks in advance
 

Attachments

  • MyGetPrimaryGoogleAccount.zip
    13.7 KB · Views: 19

aeric

Expert
Licensed User
Longtime User
Hi @hatzisn
I suggest you edit the title to be more descriptive, add the code section where the error is occuring and the error message in text.
This will help future members looking for same problem.
It will also help you getting faster answer if the forum search engine able to match your question with existing similar threads.
 
Upvote 0

teddybear

Well-Known Member
Licensed User
B4X:
Public Sub GetPrimaryAccount As String
    Dim r As Reflector
    Dim sRet As String

    Dim j As JavaObject = Me
    'j.InitializeContext
    sRet = j.RunMethod("getEmailID", Array As Object(r.GetContext))

    Return sRet

End Sub

Or move the inline java into Main module.
 
Last edited:
Upvote 1

OliverA

Expert
Licensed User
Longtime User
Note: If all you use the Reflector library for is to get the context, you can also do that with JavaObject and not use the Reflector library:


Sample code using JavaObject to call inline Java within a B4X class:
Public Sub GetPrimaryAccount As String
    Dim sRet As String
    Dim nativeMe As JavaObject = Me
    Dim ctx As JavaObject
    ctx.InitializeContext
    
    sRet = nativeMe.RunMethod("getEmailID", Array As Object(ctx))
 
    Return sRet
End Sub

Since the inline Java is within a Class (not Activity/Service/Module), don't use static qualifier
 
Upvote 1

hatzisn

Expert
Licensed User
Longtime User
Thank you both. I used both solutions for this library. You can find it here:

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