Search code examples
javapythonmacospython-2.7jpype

Class not found error on Jpype


I have read and searched all stack overflow .. I also found JPype class not found but it didn't help me although it is solved! I have the same problem ! I am using Mac , python 2.7.6

My both python code and A.java are on desktop. But I keep receiving this error :

Traceback (most recent call last): File "/Users/jeren/Desktop/aa.py", line 13, in A = jpype.JClass("A") File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/jpype/_jclass.py", line 54, in JClass raise _RUNTIMEEXCEPTION.PYEXC("Class %s not found" % name) java.lang.ExceptionPyRaisable: java.lang.Exception: Class A not found

aa.py : import jpype

import os

jpype.startJVM(jpype.getDefaultJVMPath(), "-ea", "-Djava.class.path=/Users/jeren/Desktop/")

A = jpype.JClass("A")

a = A()

jpype.shutdownJVM()

A.java :

class A

{

    public A()

    {

        super();

    }

    public String sayHi()

    {

        return("Hello");

    }



    public static void main(String[] argv)

    {

        System.out.println ("Hello ");

    }



    public static int add(int a, int b)

    {

        return(a+b);

    }

}

My mac , java and python are all 64bit ! where the problem can be?


Solution

  • everything was ok just needed to add a 'public' to the beginning of class A:

        public class A
        {       
            public A()       
            {
                super();
            }
            public String sayHi()
    
            {
                return("Hello");
            }