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

__javaclass__ definition missing #193

Closed
NetBUG opened this issue Dec 20, 2015 · 14 comments
Closed

__javaclass__ definition missing #193

NetBUG opened this issue Dec 20, 2015 · 14 comments

Comments

@NetBUG
Copy link

NetBUG commented Dec 20, 2015

Hello!
I've build pyjnius from sources on Ubuntu 14.04 and get the following error after installation:
root@staging:/tmp/pyjnius# make tests (cd tests; env CLASSPATH=../build/test-classes:../build/classes PYTHONPATH=..: nosetests -v) Failure: JavaException (__javaclass__ definition missing) ... ERROR Failure: JavaException (__javaclass__ definition missing) ... ERROR
...and all 16 tests fail.

I did to to have jnius_config module that is missing in pip package.

Detailed error:
`======================================================================

ERROR: Failure: JavaException (javaclass definition missing)

Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/nose/loader.py", line 418, in loadTestsFromName
addr.filename, addr.module)
File "/usr/local/lib/python2.7/dist-packages/nose/importer.py", line 47, in importFromPath
return self.importFromDir(dir_path, fqname)
File "/usr/local/lib/python2.7/dist-packages/nose/importer.py", line 94, in importFromDir
mod = load_module(part_fqname, fh, filename, desc)
File "/tmp/pyjnius/tests/test_bad_declaration.py", line 5, in
from jnius import JavaException, JavaClass
File "build/bdist.linux-x86_64/egg/jnius/init.py", line 13, in
File "build/bdist.linux-x86_64/egg/jnius/reflect.py", line 14, in
File "/usr/lib/python2.7/dist-packages/six.py", line 617, in with_metaclass
return meta("NewBase", bases, {})
File "jnius/jnius_export_class.pxi", line 43, in jnius.MetaJavaClass.new (jnius/jnius.c:17159)
meta.resolve_class(classDict)
File "jnius/jnius_export_class.pxi", line 56, in jnius.MetaJavaClass.resolve_class (jnius/jnius.c:17474)
raise JavaException('javaclass definition missing')
JavaException: javaclass definition missing`

@zhuanhao-wu
Copy link

Got the same error on Ubuntu 14.04

Here is my simple python code

from jnius import autoclass
import jnius_config

jnius_config.set_classpath('.', '/usr/local/fem/plugins/*')
import jnius

Test = autoclass('Test.Test')
Test.hello()

and got this error:

Traceback (most recent call last):
  File "test.py", line 1, in <module>
    from jnius import autoclass
  File "/usr/local/lib/python2.7/dist-packages/jnius-1.1_dev-py2.7-linux-x86_64.egg/jnius/__init__.py", line 13, in <module>
    from .reflect import *
  File "/usr/local/lib/python2.7/dist-packages/jnius-1.1_dev-py2.7-linux-x86_64.egg/jnius/reflect.py", line 14, in <module>
    class Class(with_metaclass(MetaJavaClass, JavaClass)):
  File "/usr/lib/python2.7/dist-packages/six.py", line 617, in with_metaclass
    return meta("NewBase", bases, {})
  File "jnius/jnius_export_class.pxi", line 43, in jnius.MetaJavaClass.__new__ (jnius/jnius.c:17159)
  File "jnius/jnius_export_class.pxi", line 56, in jnius.MetaJavaClass.resolve_class (jnius/jnius.c:17474)
jnius.JavaException: __javaclass__ definition missing

@xyzrico
Copy link

xyzrico commented Jan 22, 2016

Hello Guys. I'm in the same situation with Lubuntu in virtual box from kivy installation.
Is there any solution to resolve this?

@pdelboca
Copy link

pdelboca commented Feb 9, 2016

Which version of six.py are you using? Mine is working fine with six.py=1.10.0 with python 3.5.1.

I know it's not a professional solution but for me worked upgrading the package in the virtual env with the following command:
pip install --upgrade git+git://github.com/kivy/pyjnius.git
My solution was working just fine but after trying to install another packages in the virtual env it started throwing this error. I think the problem was in the version of the six.py my venv was using because it was updated to 1.10 when upgrading jnius and it started working again.

@xyzrico
Copy link

xyzrico commented Feb 11, 2016

I've tried
pip install --upgrade git+git://github.com/kivy/pyjnius.git
But it's still not working. javaclass definition missing

or is it my installation of java ?

@kived
Copy link
Contributor

kived commented Feb 11, 2016

Please upgrade the six package to at least version 1.7.0.

@xyzrico
Copy link

xyzrico commented Feb 13, 2016

My version of six is already up to date. Now I've done

pip install six=1.7.0

But got the same mistake.
If you want to see the output...

@kived
Copy link
Contributor

kived commented Feb 13, 2016

The source shown in your traceback is from a pre-1.7.0 version.

This is the code from 1.7.0:

def with_metaclass(meta, *bases):
    """Create a base class with a metaclass."""
    # This requires a bit of explanation: the basic idea is to make a
    # dummy metaclass for one level of class instantiation that replaces
    # itself with the actual metaclass.  Because of internal type checks
    # we also need to make sure that we downgrade the custom metaclass
    # for one level to something closer to type (that's why __call__ and
    # __init__ comes back from type etc.).
    class metaclass(meta):
        __call__ = type.__call__
        __init__ = type.__init__
        def __new__(cls, name, this_bases, d):
            if this_bases is None:
                return type.__new__(cls, name, (), d)
            return meta(name, bases, d)
    return metaclass('temporary_class', None, {})

I confirmed that everything worked in 1.7.0 and later versions, and didn't work in pre-1.7.0 versions.

Your issue is most likely that you have two different versions of six installed. The one from Lubuntu (package python-six) is installed to /usr/lib/python2.7/dist-packages, which is what is listed in your traceback, and is not where pip installs. You should try removing the pip installed version and updating the system package via apt (don't uninstall python-six and keep the pip version, this package is necessary for many other system packages).

@xyzrico
Copy link

xyzrico commented Feb 13, 2016

If I get you right, I should try

pip uninstall six

Or please can you juste paste me the commands I should type ?
The package python-six is installed. and my version of six got by pip is 1.7.0

@danielepantaleone
Copy link
Contributor

Use pip install six -U.
In addition, you can check what version of six you have currently installed by typing pip freeze.

@xyzrico
Copy link

xyzrico commented Feb 14, 2016

My current installation of six is 1.10.0.
so... what should I do next ?

@xyzrico
Copy link

xyzrico commented Feb 15, 2016

so... what should I do next ?

@kived
Copy link
Contributor

kived commented Feb 15, 2016

Well if you still have this issue then you are still using a version of six < 1.7.0. Make sure you aren't using a virtualenv including an old version, or that you have something in your PYTHONPATH pointing to another location.

@xyzrico
Copy link

xyzrico commented Feb 18, 2016

I'm not using virtualenv at all. But I found in my sys.path
a path to folder containing an old version of six (1.5.2). So I removed it.
Now when I type

from jnius import autoclass, cast

I get an KeyError: 'JAVA_HOME'

My Java folder is '/usr/lib/jvm/java-1.7.0-openjdk-amd64'
so i set

export JAVA_HOME=/usr/lib/jvm/java-1.7.0-openjdk-amd64
and in python i typed

from jnius import autoclass, cast

and it Worked !!!
Thank you for your help.

@danielepantaleone
Copy link
Contributor

Make sure to set your JAVA_HOME environment variable to the correct path of your java home. If you are on Windows you need also to add the path to the jvm.dll to system Path.

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

No branches or pull requests

6 participants