AttributeError: 'long' object has no attribute '__tojava__' - jython

I browsed the javadoc for PyInteger and found it supports api tojava. However, when I run the following script, error happens.
n=1
n.__tojava__(java.math.BigInteger)
AttributeError: 'long' object has no attribute '_tojava_'
I found only the api which is written with pure python could be called successfully. For other apis, there are always errors, saying "xxx object has no attribute 'xxx'". Is there any configuration I should do?

if all you want is a BigInteger, you an just construct an instance using the string constructor
x=java.math.BigInteger('1')
or in your case
x=java.math.BigInteger(str(n))

Related

AttributeError: 'RangeIndex' object has no attribute 'stop'

I'm using a library that gives me access to a RangeIndex object while iterating. I'm having trouble finding out how to access the integer index from this object. If i print the object i see that the "stop" parameter seems to be the index i want (not sure though). However when i try to print the stop parameter i get this error message. Though when i look at source code i see that all instances of RangeIndex look to have this parameter. I tried searching up how to get an index for RangeIndex and there isn't much on this particular object.

Janino Compile Exception : UDJC step

Thanks in advance for your support.
In UDJC step, the following code gives me Janino exception,
In processRow method
Hashtable hastable=getConfigData() // This method return Hashtable
Set set=hashtable.get("ERROR_2001").keySet(); ---> //hashtable.get("ERROR_2001"), This returns another hashtable
Exception:
A method named "keySet" is not declared in any enclosing class nor any supertype, nor through a static import
In forums I could not find the turn around solution to fix this. I am using JDK 1.7 and PDI 5.1 (latest download)
AFAIK, you can't use generics in Janino, so Janino can not determine exact class of the object returned by hashtable.get("ERROR_2001") method, so it assumes that Object is returned, which has no keySet() method defined.
Try to cast the result of hashtable.get("ERROR_2001") to the value class, contained in your hashtable collection:
Hashtable errorEntry = (Hashtable) hashtable.get("ERROR_2001");
Set set = errorEntry.keySet();

Kotlin: Method reference not working?

It seems I'm unable to use a method reference of an object in Kotlin. This feature exists in Java.
For example in Java if I was looping through a string to append each character to a writer:
string.forEach(writer::append);
But in Kotlin using the same syntax does not work because:
For now, Kotlin only supports references to top-level and local functions and members of classes, not individual instances. See the docs here.
So, you can say Writer::append and get a function Writer.(Char) -> Writer, but taking a writer instance and saying writer::append to get a function (Char) -> Writer is not supported at the moment.
Starting from Kotlin 1.1 writer::append is a perfectly valid bound callable reference.
However, you still cannot write string.forEach(writer::append) because Writer#append method returns a Writer instance and forEach expects a function that returns Unit.
I am using Kotlin 1.3 and while referencing a Java method I got a very similar error. As mentioned in this comment, making a lambda and passing it to the forEach method is a good option.
key.forEach { writter.append(it) }
Being it the implicit name of a single parameter.

Pygame AttributeError: 'module' object has no attribute 'copy'

I encountered Error: 'module' object has no attribute 'copy' while running a pygame program. In my code, I never referred to a copy attribute, so I don't understand where the error is coming from.
I think there is a python file named "copy" in your directory. I had the same problem, after I delete the "copy" file, the error has gone.

JPype: how to convert the boolean value from python to java

I want to run java class in my python code and I use the tool JPype.
I have a java method with a boolean argument.
It works in java code but when I call it in python, I get the error message:
RuntimeError: No matching overloads found. at src/native/common/jp_method.cpp:121
I even use the jpype wrapper JBoolean, but it still fails.
For example, the code in java is:
item.myMethod(true);
and I have tried to convert it in python as:
item.myMethod(1)
item.myMethod(True)
item.myMethod(jpype.JBoolean(True))
item.myMethod(jpype.JBoolean(1))
but all of above get the same error message.
Could anyone help me to convert the boolean argument from python to java??
thank you!!
Is the argument of your Java method defined as a boolean or a java.lang.Boolean?
If it is boolean, then all the possibilities you have tried should work (if not there might be something wrong with the way you import the Class in your Python code). However, if it's a java.lang.Boolean, then you have to call your method as such:
item.myMethod(jpype.java.lang.Boolean(True))