gpt4 book ai didi

classpath - java.lang.NoClassDefFoundError : Could not initialize class sun. nio.ch.FileChannelImpl 错误

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:28:15 26 4
gpt4 key购买 nike

我正在开发一个从 JAVA 1.6.027 执行 Jython 2.5.3 脚本的应用程序。该脚本只是使用编解码器库打开一个文件,它看起来像这样:

try:
from codecs import open as codecs_open
except ImportError:
print 'ERROR', 'Could not import.'

CODECS_LIST = ['latin-1', 'utf-8', 'utf-16', '1250', '1252']

def open_file(filename, mode):
'''
DOC
'''
for encoding in CODECS_LIST:
try:
f = codecs_open(filename, mode, encoding)
f.read()
f.close()
print 'INFO', "File %s supports encoding %s." % (filename.split("\\")[-1], encoding)
...
except:
...

当我在Eclipse 中执行此脚本调试时,一切正常,但是当我执行调用此脚本的JAVA 应用程序部分时,出现此错误:

Exception in thread "main" java.lang.NoClassDefFoundError: Could not initialize class sun.nio.ch.FileChannelImpl
at java.io.RandomAccessFile.getChannel(RandomAccessFile.java:253)
at org.python.core.io.FileIO.fromRandomAccessFile(FileIO.java:173)
at org.python.core.io.FileIO.<init>(FileIO.java:79)
at org.python.core.io.FileIO.<init>(FileIO.java:57)
at org.python.core.PyFile.<init>(PyFile.java:135)
at org.python.core.PyTraceback.getLine(PyTraceback.java:65)
at org.python.core.PyTraceback.tracebackInfo(PyTraceback.java:38)
at org.python.core.PyTraceback.dumpStack(PyTraceback.java:109)
at org.python.core.PyTraceback.dumpStack(PyTraceback.java:120)
at org.python.core.Py.displayException(Py.java:1080)
at org.python.core.PySystemState.excepthook(PySystemState.java:1242)
at org.python.core.PySystemStateFunctions.__call__(PySystemState.java:1421)
at org.python.core.Py.printException(Py.java:1053)
at org.python.core.Py.printException(Py.java:1012)
at org.python.util.jython.run(jython.java:264)
at org.python.util.jython.main(jython.java:129)

JAVA 应用程序能够执行其他类似的 jython 脚本。我检测到 class sun.nio.ch.FileChannelImpl 位于库 rt.jar 中,它位于 /bin/common/ 文件夹中并包含在我的 classpath 通过 jvm.cfg 文件:

...    
#LIBRARY PATH
./bin/common;...
...

我对其他运行良好的库采用相同的方式。

我已经被这个问题困扰了好几天,所以任何帮助都将不胜感激。谢谢

最佳答案

问题已通过重新安装 Java Runtime Environment 解决,在我的例子中是版本 jre-6u45

关于classpath - java.lang.NoClassDefFoundError : Could not initialize class sun. nio.ch.FileChannelImpl 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18444785/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com