TransWikia.com

Java HashMap in Python Code throwing Error

Stack Overflow Asked by Pritiraj on December 13, 2021

I need to use HashMap in Python code.

I am writing this line in Pycharm, using Python:

jhash = java.util.HashMap

I have imported like this:

import jpype
from jpype import java
from jpype import javax

But i am getting below error:

Traceback (most recent call last):
File "C:/PythonCode/JMX.py", line 11, in <module>
  jhash = java.util.HashMap()
TypeError: Package `java.util.HashMap` is not callable.

One Answer

Even with this little code I could reproduce the error. In my opinion you didn't start JVM. This code works fine for me.

import jpype
from jpype import java

jpype.startJVM()
jhash = java.util.HashMap()
jhash.put("A","B")

print(jhash)

Answered by tifi90 on December 13, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP