Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Callback is not working #586

Closed
jain18aditya opened this issue Mar 23, 2021 · 6 comments
Closed

Callback is not working #586

jain18aditya opened this issue Mar 23, 2021 · 6 comments
Labels

Comments

@jain18aditya
Copy link

I am trying to implement callback from Java to python using pyjnius

My Code:
TestClass.py

            dataStoreClientPackage  = autoclass('com.test.TestClient')
            handle = testClientPackage(Context)
            print(handle)

            serviceConnection = Service_Connection_Callback()
            handle.connect(Constants.DATA_DIR, Constants.namespace, serviceConnection, None)

ServiceConnectionCallback.py

from jnius import PythonJavaClass, java_method

class Service_Connection_Callback(PythonJavaClass):
    __javainterfaces__ = ['test/callback/ServiceConnectionCallback']

    actualResult = ""
    @java_method('()Z')
    def onConnect(self) :
        print ("Connected")

    @java_method('()Ljava/lang/Object;')
    def onFailure(self, err) :
        print("Failed to connect with error "+ err)

While running i am getting below error:

Test/ds_init/TestInit.py:85: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
jnius/jnius_export_class.pxi:857: in jnius.JavaMethod.__call__
    ???
jnius/jnius_export_class.pxi:954: in jnius.JavaMethod.call_method
    ???
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

>   ???
E   jnius.JavaException: JVM exception occurred: Stub! java.lang.RuntimeException

jnius/jnius_jvm_dlopen.pxi:91: JavaException

I believe this is in callback but not able to RC or fix this?

@hx2A
Copy link
Member

hx2A commented Mar 23, 2021

I think we will need to see more of your code to help here. The serviceConnection is being passed to handle.connect, but what does that connect method do? What calls does it make to serviceConnection? Also, where is the Java code for 'test/callback/ServiceConnectionCallback'? Is that an Interface?

@jain18aditya
Copy link
Author

connect method connects to a system service which accepts above 4 params, handle.connect(Constants.DATA_DIR, Constants.namespace, serviceConnection, None)
First is path, second is db name, 3rd is Service Connection callback and 4th is listner but it accepts none as well.

test/callback/ServiceConnectionCallback'?
Yes this is an interface

Code:

public interface ServiceConnectionCallback {
    void onConnect();
    void onFailure(String errorMessage);
}

@hx2A
Copy link
Member

hx2A commented Mar 24, 2021

I see your signature for onFailure is different. Your Java code has it with a String parameter and returning void, but in Python it has no parameters and returns an object.

@jain18aditya
Copy link
Author

Are you pointing out here:

` javainterfaces = ['test/callback/ServiceConnectionCallback']

actualResult = ""
@java_method('()Z')
def onConnect(self) :
    print ("Connected")

@java_method('()Ljava/lang/Object;')
def onFailure(self, err) :
    print("Failed to connect with error "+ err)`

What is it supposed to be in that case. My java coed is correct and.i want to implement same in Python

@jain18aditya
Copy link
Author

jain18aditya commented Mar 25, 2021

I have added logs in callback class before any method and it is not reaching to that point either, So i believe this error is not related to the error i am getting.

class Service_Connection_Callback(PythonJavaClass):
    print("I am coming to callback")
    __javainterfaces__ = ['test/callback/ServiceConnectionCallback']

    actualResult = ""
    @java_method('()V')
    def onConnect(self) :
        print ("Connected")

    @java_method('(Ljava/lang/String;)V')
    def onFailure(self, err) :
        print("Failed to connect with error "+ err)

@github-actions
Copy link

👋 We use the issue tracker exclusively for bug reports and feature requests. However, this issue appears to be a support request. Please use our support channels to get help with the project.
Let us know if this comment was made in error, and we'll be happy to reopen the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants