Menu

JArray Frustration

Feedback
2009-06-26
2013-04-25
  • C. Martin Taylor

    Back in 2005 I posted a message to this forum (https://sourceforge.net/forum/forum.php?thread_id=1391722&forum_id=379372) that was never answered.  I haven't used JPype much in the intervening years, but now I'm trying to use it again and getting the same problem with JArray.  Here's today's example:

    >>> from jpype import *
    >>> a = JArray(JByte)
    >>> a
    <class 'jpype._jarray.byte[]'>
    >>> b = a(10)
    Traceback (most recent call last):
      File "<interactive input>", line 1, in <module>
      File "C:\Python25\Lib\site-packages\jpype\_jarray.py", line 73, in _jarrayInit
        _JavaArrayClass.__init__(self, _jpype.newArray(self.__class__.__javaclass__, sz))
    TypeError: argument 1 must be PyCObject, not None

    I'm using ActivePython 2.5.1.1.  Am I not doing something right? Or could this be a problem with my version of Python?

    Any help to get this working would be greatly appreciated.  If I don't get a solution by Monday I may have to switch to Jython and access Java that way.

    Thanks,
    Martin

     
    • C. Martin Taylor

      Boy do I feel dumb now!  I forgot to do

      startJVM(r"C:\java\jdk1.6.0_01\jre\bin\client\jvm.dll", "-ea")

      before doing the steps above.  I do this in my code all the time, but I forgot to do it in the interactive Python session. 

      It would be a big improvement to JPype if it gave an error message like "Must call startJVM first" if any other method is attempted before doing this.

       

Log in to post a comment.