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

invoke java method error. #431

Closed
ysong2123 opened this issue Jul 12, 2019 · 2 comments
Closed

invoke java method error. #431

ysong2123 opened this issue Jul 12, 2019 · 2 comments
Labels

Comments

@ysong2123
Copy link

ysong2123 commented Jul 12, 2019

here is my issue:
in java: i have defined a Class Calculator which contains method -- public Value run(Value... inputs). And a little test data has been prepared for testing this method --

    Value[] inputs = new Value[2];
    inputs[0] = Value.create(0.6);
    inputs[1] = Value.create(0.7);

and then run calculator.run(inputs).

Now, for business purpose, i have to implement this unit test using python again and the corresponding java class: Value and Calculator will be reused by leveraging jnius. Here is my python code:
solution 1:

    ArrayList = autoclass('java.util.ArrayList')
    list = ArrayList()
    list.add(Value.create(0.6))
    list.add(Value.create(0.7))
    calculator.run(list.toArray())

and then the exception has been thrown:
jnius.JavaException: JVM exception occurred: java.lang.ArrayStoreException.

solution 2:

import numpy as np
inputs = [Value.create(0.6), Value.create(0.7)]
calculator.run(np.array(inputs))
and then thrown:
jnius.JavaException: Invalid variable (array([<com/***/Value at 0x7f8a985599e8 jclass=com/***/Value jself=<LocalRef obj=0x7f8ac3d751f8 at 0x7f8a9852c4b0>>,
       <com.***.Value at 0x7f8a98559990 jclass=com/***/Value jself=<LocalRef obj=0x7f8ac3d751f0 at 0x7f8a9852c930>>],
      dtype=object),) used for L array 'Lcom/***/Value;'

Do you know how to implement the same semantics as shown in java?

Value[] inputs = new Value[2];
    inputs[0] = Value.create(0.6);
    inputs[1] = Value.create(0.7);

and then run calculator.run(inputs).

Thanks very much!

@ysong2123
Copy link
Author

Thanks a lot!

@github-actions
Copy link

👋 We use the issue tracker exclusively for bug reports and feature requests. However, this issue appears to be a support request. Please use our support channels to get help with the project.
Let us know if this comment was made in error, and we'll be happy to reopen the issue.

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

No branches or pull requests

2 participants