我已经开始使用 Pyjnius 并且遇到了一个严重的错误。我没有找到任何关于它的参考,但它很容易获得,我严重怀疑我是第一个体验它的人。
基本上,如果我尝试通过一个实例访问一个类的静态成员,我会遇到整个 Python 解释器的崩溃,除非我之前通过该类为该成员分配了一个值。
我的 JAVA 类是这样的:
class TestClass {
public static int b;
public double c;
public TestClass(int cc) {
c = cc;
}
}
我的测试 Python 脚本很简单:
from jnius import autoclass
the_class = autoclass('TestClass')
the_object = the_class(42.0) # create an instance
print(the_object.c) # no problem accessing the non-static member
the_object.c = 12.56
print(the_object.c) # no problem modifying the non-static member
print(the_class.b) # no problem accessing the static member from the class
#print(the_object.b) # crash if I access the static member from the instance!!!!
the_class.b = 42
print(the_class.b) # no problem modifying the static member from the class
print(the_object.b) # and now I can also access it from the instance, but only after I have modified it
现在,如果我在从类中修改它的值之前取消注释访问 the_object.b 的行,我会得到 Python 解释器的完全崩溃。
如果我访问类的任何数字或字符串成员,但不会访问静态方法,也会发生同样的崩溃:我可以从实例访问它们而不会出现问题。
我正在运行:
视窗 10
Python 3.6.2
Pyjnius 1.1.1
Java 1.8.0_161
有没有人有同样的行为,或者你能提出任何解决方案吗?