Argument type mismatch

113 views
Skip to first unread message

bev...@gmail.com

unread,
May 8, 2014, 11:36:22 PM5/8/14
to pyjni...@googlegroups.com
Hello,

Thanks for Pyjnius.  I am trying to use it to access Java classes.   I am looking for info on how to create and populate a HashMap

I have
accessfactory = autoclass('factory.AccessFactory')
options = autoclass('java.util.HashMap')
#AccessFactory.connect(aUser, aRole, aPassword, aDomain, aHost, Integer.parseInt(aPort), new HashMap<String, Object>());
accessfactory.connect('user', 'role', 'password', 'domain', 'host', 8080, options)

which gives
dataaccess.DataException: java.lang.IllegalArgumentException: argument type mismatch
    at factory.AccessFactory.connect(AccessFactory.java:721)
Caused by: java.lang.IllegalArgumentException: argument type mismatch
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at factory.AccessFactory.connect(AccessFactory.java:713)
Traceback (most recent call last):
  File "call_dataaccess.py", line 26, in <module>
    accessfactory.connect('user', 'role', 'password', 'domain', 'wiski', 8080, options)
  File "jnius_export_class.pxi", line 561, in jnius.JavaMethod.__call__ (jnius\jnius.c:18574)
  File "jnius_export_class.pxi", line 727, in jnius.JavaMethod.call_staticmethod (jnius\jnius.c:20416)
  File "jnius_utils.pxi", line 43, in jnius.check_exception (jnius\jnius.c:3953)
jnius.JavaException: JVM exception occured
Exception in thread "main"

The method detail is

public static IDataAccess connect(String theUser,
                                       String theRole,
                                       String thePassword,
                                       String theDomain,
                                       String theServer,
                                       int thePort,
                                       HashMap<String,Object> theOptions)
                                throws DataException

    Perform an connect to the data storage.

    Parameters:
        theUser - the user name
        theRole - the role
        thePassword - the password
        theDomain - the domain
        theServer - the server host
        thePort - the server port
        theOptions - map of options
    Returns:
        IDataAccess
    Throws:
        DataException - on error

While some java to achieve the same is
 public static void main(String[] args) throws DataException {
    // Connect to the server
    IDataAccess access =
      AccessFactory.connect("user", "role", "password", "domain",
        "localhost", 8080, null);
    // Get time series object
    ITimeSeries ts =
      access.getTimeSeries("A7/Ratings/SSS/etc", null);
....


Mathieu Virbel

unread,
May 9, 2014, 4:55:23 AM5/9/14
to pyjni...@googlegroups.com
Hey,

Ok, i've no idea how to construct a specialized class with Pyjnius, this
has to be implemented i guess.

In your code, you passed a non-instancied class, which will not work.
In the Java code, null is passed.

So just use "None" instead of "options" in the connect, that should
work. However, i think there is no way to pass options right now then.

Mathieu
> --
> You received this message because you are subscribed to the Google
> Groups "PyJNIus development ML" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to pyjnius-dev...@googlegroups.com
> <mailto:pyjnius-dev...@googlegroups.com>.
> For more options, visit https://groups.google.com/d/optout.

bev...@gmail.com

unread,
May 11, 2014, 6:44:37 PM5/11/14
to pyjni...@googlegroups.com


On Friday, May 9, 2014 8:55:23 PM UTC+12, Mathieu Virbel wrote:
Hey,

Ok, i've no idea how to construct a specialized class with Pyjnius, this
has to be implemented i guess.

In your code, you passed a non-instancied class, which will not work.
In the Java code, null is passed.

So just use "None" instead of "options" in the connect, that should
work. However, i think there is no way to pass options right now then.

Thank you, I tried passing None not too long after I posted and it works. Yes in the java code i posted null is passed (maybe not the best example).  A better example is :
HashMap<String, Object> aOptions = new HashMap<String, Object>();
    aOptions.put("locale", "en");
Then pass aOptions where I was passing options

Reply all
Reply to author
Forward
0 new messages