【发布时间】:2020-07-30 17:03:52
【问题描述】:
我有一个方法如下,已经正常运行了很长时间:
private String loadFromFile(){
RandomAccessFile inFile = null;
FileChannel inChannel = null;
StringBuilder sb = new StringBuilder();
try {
inFile = new RandomAccessFile(this.latestImageFile, "r");
inChannel = inFile.getChannel();
ByteBuffer bb = ByteBuffer.allocate(2046);
while( inChannel.read(bb) != -1){
bb.flip();
while(bb.hasRemaining()){
char c = (char) bb.get(); // read character at current position and set the pointer to current position + 1
sb.append(c);
}
bb.clear();
}
} catch (IOException e) {
e.printStackTrace();
} finally {
if (inChannel != null) try {inChannel.close(); } catch (IOException e){}
if (inFile != null ) try { inFile.close(); } catch (IOException e) {}
}
return sb.toString();
}
但是,今天我在服务器上编译并运行程序后,启动程序时记录了以下异常。它显示未找到翻转()方法:
Exception in thread "main" java.lang.NoSuchMethodError: java.nio.ByteBuffer.flip()Ljava/nio/ByteBuffer;
at com.rt.stream.s.exch.OBWorker.loadFromFile(OBWorker.java:271)
at com.rt.stream.s.exch.OBWorker.initAndLoadOBs(OBWorker.java:184)
at com.rt.stream.s.exch.OBWorker.<init>(OBWorker.java:145)
at com.rt.stream.s.exch.OBWorkerMgr.initFromProperties(OBWorkerMgr.java:217)
at com.rt.stream.s.exch.OBWorkerMgr.init(OBWorkerMgr.java:132)
at com.rt.stream.s.exch.OBWorkerMgr.main(OBWorkerMgr.java:511)
请问有人知道吗?
程序运行环境规范是这样的:
服务器:
- openjdk 版本“1.8.0_242”
发展:
IDE:版本:2019-09 R (4.13.0)
JDK:jdk-11.0.1
maven: apache-maven-3.3.3(应用了以下配置)
<source>1.8</source>
<target>1.8</target>
【问题讨论】:
-
开发时为什么不能使用自己服务器的同一个jdk?
-
是的,你是对的,这将是理想的情况,应该在生产环境中完成。但是对于非生产环境的某些情况,例如我们不时在同一个 IDE 工作区中开发不同的宠物项目,甚至在与其他项目在其上运行的共享环境中运行。偶尔会遇到。
-
我在使用 Apache NetBeans 12.6 和 jdk 1.8.0_202 时遇到了同样的错误。我通过将 Apache NetBeans 降级到 12.3 解决了这个问题
标签: java java-8 java-11 bytebuffer