kivy / pyjnius

Access Java classes from Python
https://pyjnius.readthedocs.org
MIT License
1.38k stars 256 forks source link

Exception on Implement OnCompletionListener #185

Closed gonzafirewall closed 10 months ago

gonzafirewall commented 8 years ago

Hi people i have this error sometimes when i implement the OnCompletionListener

I/python (16270): 2015-11-24 08:22:46-0600 [-] Traceback (most recent call last): I/python (16270): 2015-11-24 08:22:46-0600 [-] File "jnius_proxy.pxi", line 151, in jnius.jnius.invoke0 (jnius/jnius.c:25574) I/python (16270): 2015-11-24 08:22:46-0600 [-] File "jnius_proxy.pxi", line 121, in jnius.jnius.py_invoke0 (jnius/jnius.c:25206) I/python (16270): 2015-11-24 08:22:46-0600 [-] AttributeError: 'list' object has no attribute 'invoke' F/libc (16270): Fatal signal 11 (SIGSEGV), thread 16270 (r.vixcam:python)

This error not occur all the time, some times works well and sometimes make this exception, this is my onCompletionListener

class PythonOnComplete(PythonJavaClass):                                     
     __javainterfaces__ = ['android/media/MediaPlayer$OnCompletionListener']  
     def __init__(self, websocket, *args, **kwargs):                          
         self.ws = websocket                                                  
         super(PythonOnComplete, self).__init__(*args, **kwargs)              

     @java_method('(Landroid/media/MediaPlayer;)V')                           
     def onCompletion(self, mp):                                              
         del self.ws.last_song                                                
         print "[PYTHON_ON_COMPLETE]" +" termino el tema"   

--- Want to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/28570292-exception-on-implement-oncompletionlistener?utm_campaign=plugin&utm_content=tracker%2F77133&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F77133&utm_medium=issues&utm_source=github).
dushujun commented 5 years ago

Any advice?

vesellov commented 4 years ago

I have the same ...

AndyRusso commented 2 years ago

Any advice, guys?

RobertFlatt commented 2 years ago

Wrap your head around this. An overview of this approach is described here: https://github.com/Android-for-Python/Android-for-Python-Users#calling-python-from-java

Links to an example follow (it has 3 listeners, one of which is onCompletion):

Write the completion listener in Java, for example: https://github.com/Android-for-Python/Face-Detect-Example/blob/main/mlkit_src/org/kivy/mlkit/CompleteListener.java . Using the Callback wrapper described above ( for this example I used https://github.com/Android-for-Python/Face-Detect-Example/blob/main/mlkit_src/org/kivy/mlkit/CallbackWrapper.java ).

Those classes are then used in Python like this: https://github.com/Android-for-Python/Face-Detect-Example/blob/main/facedetect.py#L29-L30

https://github.com/Android-for-Python/Face-Detect-Example/blob/main/facedetect.py#L33-L49

https://github.com/Android-for-Python/Face-Detect-Example/blob/main/facedetect.py#L63-L66

https://github.com/Android-for-Python/Face-Detect-Example/blob/main/facedetect.py#L93

A Python method is thus called from a Java onCompletionListener.

github-actions[bot] commented 10 months ago

👋 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.