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

JavaException when calling Java methods stored in Python class variables #47

Open
JoshRosen opened this issue Dec 27, 2012 · 0 comments
Labels

Comments

@JoshRosen
Copy link

JoshRosen commented Dec 27, 2012

I ran across a confusing JavaException when trying to call a Java method stored in a class variable:

from jnius import autoclass                                                     

System = autoclass('java.lang.System')                                          

# This works:                                                                   
System.out.println('Hello World')                                               
map(System.out.println, ['Hello World'])                                        
println = System.out.println                                                    
map(println, ['Hello World'])                                                   

class MyClass(object):                                                          
    def __init__(self):                                                         
        self.println = System.out.println  # Instance variables are fine                                      
map(MyClass().println, ['Hello World'])                                         

# This causes an exception:                                                                 
class MyClass(object):                                                          
    println = System.out.println  # But class variables cause errors                                          
map(MyClass.println, ['Hello World'])

Running this code produces the following output:

Hello World
Hello World
Hello World
Hello World
Traceback (most recent call last):
  File "jniustest.py", line 19, in <module>
    map(MyClass.println, ['Hello World'])
  File "jnius_export_class.pxi", line 745, in jnius.JavaMultipleMethod.__call__ (jnius/jnius.c:15502)
jnius.JavaException: No methods matching your arguments

This is an odd edge-case with an easy workaround (don't store Java methods in class variables), but I thought I'd report it here in case anyone else encounters it.

--- Want to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/1362787-javaexception-when-calling-java-methods-stored-in-python-class-variables?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).
@dessant dessant changed the title JavaException when calling Java methods stored in Python class variables JavaException when calling Java methods stored in Python class variables Jan 15, 2015
@Julian-O Julian-O removed the support label Oct 25, 2023
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