java - Jython 给出“无法创建具有非字节值的 PyString”错误
问题描述
我的代码:
from javax.swing import JFrame
frame = JFrame("Hello")
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE)
frame.setLocation(100,100)
frame.setSize(300,200)
frame.setVisible(True)
但是我无法在 cmd 中打开 jython 它给出了这个错误,我知道为什么会这样。当我用 jython(eclipse) 在 java 中做同样的事情时,它的工作原理。
C:\>jython banana.py
Exception in thread "main" java.lang.ExceptionInInitializerError
at org.python.core.PySystemState.<clinit>(PySystemState.java:73)
at org.python.util.jython.main(jython.java:533)
Caused by: java.lang.IllegalArgumentException: Cannot create PyString with non-byte value
at org.python.core.PyString.<init>(PyString.java:57)
at org.python.core.PyString.<init>(PyString.java:70)
at org.python.core.PyString.<init>(PyString.java:74)
at org.python.core.Py.newString(Py.java:643)
at org.python.core.PyJavaType.init(PyJavaType.java:543)
at org.python.core.PyType$Registry.createType(PyType.java:477)
at org.python.core.PyType$Registry.addFromClass(PyType.java:426)
at org.python.core.PyType$Registry.resolveType(PyType.java:352)
at org.python.core.PyType$Registry$1.computeValue(PyType.java:208)
at org.python.core.PyType$Registry$1.computeValue(PyType.java:202)
at java.base/java.lang.ClassValue.getFromHashMap(ClassValue.java:226)
at java.base/java.lang.ClassValue.getFromBackup(ClassValue.java:208)
at java.base/java.lang.ClassValue.get(ClassValue.java:114)
at org.python.core.PyType.fromClass(PyType.java:2137)
at org.python.core.PyObject.<init>(PyObject.java:85)
at org.python.core.PySingleton.<init>(PySingleton.java:9)
at org.python.core.PyNotImplemented.<init>(PyNotImplemented.java:10)
at org.python.core.Py.<clinit>(Py.java:66)
... 2 more
但jython --version
运行良好,jython 给出了相同的错误输出。我卡住了
解决方案
这似乎是某些 Windows 10 Pro 实例的问题(请参阅:https ://bugs.jython.org/issue2890 )。
至于解决方案,您可以尝试附加调试器或将以下 println 添加到 PyJavaType.java 以打印出反映的类:
// Fill in the __module__ attribute of PyReflectedFunctions.
if (reflectedFuncs.size() > 0) {
if (nameSpecified == null) {
System.out.println(name);
nameSpecified = Py.newString(name);
}
for (PyReflectedFunction func : reflectedFuncs) {
func.__module__ = nameSpecified;
}
}
样本输出:
C:\java -jar jython-standalone-2.7.2.jar
reflectedconstructor
reflectedfield
reflectedfunction
beanproperty
java.lang.Object
java.lang.reflect.AnnotatedElement
java.lang.reflect.GenericDeclaration
java.lang.reflect.Type
java.lang.Class
singleton
notimplemented
javapackage
org.python.core.JavaImporter
.
.
.
我怀疑这与“未实现”类(来自堆栈跟踪)有关。我无法在 Win 10 Pro 上重现。
推荐阅读
- r - 使用带有glue_data 的数据框列名
- c - 是否可以在以后的循环迭代中增加模运算符?
- java - 如何判断一段java代码是否是heap-allocation-free的?
- twilio - 无论实际结果如何,Twilio 始终返回“进行中”
- python - 如何在 python 测试中模拟 subprocess.check_call 异常
- flex-lexer - 设置 %option prefix= 时如何让 automake 识别 flex 生成的非默认文件名
- regex - 如何在标题右侧正则表达式匹配(删除)任意一系列以逗号分隔的两字母语言代码?
- python-3.x - 字典列表:合并、排序和挑选前 (n) 个条目
- sql - 如果不存在,则将 Table1 中的数据插入到 Table2 中,否则更新 table2 中的数据以匹配 Table1。在任何一种情况下,从 Table1 中删除
- asp.net-core - 错误 MSB3644:找不到框架“.NETFramework,Version=v5.0”的参考程序集