pyjnius icon indicating copy to clipboard operation
pyjnius copied to clipboard

Getting error `AttributeError: 'Class' object has no attribute '_JavaClass__cls_storage'` whlie using autoclass

Open vikramahuja1001 opened this issue 4 years ago • 3 comments

Hi, Using jnius version: '1.1.0' I am running the following code on python 2.7: from jnius import autoclass self.r = autoclass('java.util.Stack')

I am getting the error : Traceback (most recent call last): File "/snap/pycharm-community/256/plugins/python-ce/helpers/pydev/_pydevd_bundle/pydevd_exec.py", line 3, in Exec exec exp in global_vars, local_vars File "<input>", line 1, in <module> File "/home/vikram/PycharmProjects/pythonProject/venv/lib/python2.7/site-packages/jnius/reflect.py", line 158, in autoclass c = find_javaclass(clsname) File "jnius/jnius_export_func.pxi", line 27, in jnius.find_javaclass File "jnius/jnius_export_class.pxi", line 153, in jnius.JavaClass.__init__ AttributeError: 'Class' object has no attribute '_JavaClass__cls_storage'

I tried running them separately and got the same result. What should i do to solve this issue? Is it even possible?

Thanks

vikramahuja1001 avatar Nov 10 '21 12:11 vikramahuja1001

java.util.Stack is an interface. not sure it make sense to autoclass it.

cmacdonald avatar Nov 10 '21 12:11 cmacdonald

Same error for jnius.autoclass('java.lang.Boolean') and autoclass('java.lang.System') as well

vikramahuja1001 avatar Nov 10 '21 12:11 vikramahuja1001

jnius 1.1 is quite old. Can you migrate to Python 3 and more recent Jnius:

python
Python 3.7.11 (default, Jul 27 2021, 07:03:16) 
[Clang 10.0.0 ] :: Anaconda, Inc. on darwin
Type "help", "copyright", "credits" or "license" for more information.
im>>> import jnius
>>> jnius.__version__
'1.3.0'
>>> jnius.autoclass('java.lang.Boolean')
<class 'jnius.reflect.java.lang.Boolean'>

cmacdonald avatar Nov 10 '21 12:11 cmacdonald

Closing as the issue refers on a old version of pyjnius, and we do not support Python 2.7 anymore. Feel free to re-open the issue if it persists on a recent pyjnius version (on a supported Python 3 version)

misl6 avatar Oct 07 '23 12:10 misl6