相关疑难解决方法(0)

java.nio.Buffer没有在运行时加载clear()方法

所以我是一个使用java代理注入的项目的开发人员.应该注意的是,在调用main之后会发生此错误.

对于大多数用户来说一切都很顺利,但是有一些问题是java.nio.IntBuffer没有加载clear()(继承自Buffer)

错误:

java.lang.NoSuchMethodError: java.nio.IntBuffer.clear()Ljava/nio/IntBuffer;
Run Code Online (Sandbox Code Playgroud)

然后在我们的代码中调用stacktrace,它简单地给出第一次clear().

造成这种情况的原因(除了Java没有在运行时加载)以及如何解决它?

java buffer nio

7
推荐指数
1
解决办法
2204
查看次数

包 sun.awt 不存在

当使用ant, 调用sun.awt.AppContext工作时,但是使用 AdaptOpenJDK11 使用 IntelliJ 编译的相同代码失败。

  • sun.awt.AppContext使用Oracle JDK8与 IntelliJ 配合使用
  • sun.awt.AppContext采用AdoptOpenJDK11不适用于IntelliJ

尽管 Sun/Oracle 已经警告过一段时间要避免使用这些sun.*包,但Java中的某些功能(错误?)仍然需要它们,而且很奇怪,命令行似乎很高兴。

示例代码:

package test;

import javax.print.PrintService;
import javax.print.PrintServiceLookup;
import sun.awt.AppContext;

public class Main {

    public static void main(String[] args) {
        //Update printer list in CUPS immediately
        AppContext.getAppContext().put(PrintServiceLookup.class.getDeclaredClasses()[0], null);

        PrintService[] printers = PrintServiceLookup.lookupPrintServices(null, null);
        for (PrintService p : printers) {
            System.out.println(p.getName());
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

如何配置 IntelliJ 使其表现得像ant并允许访问sun.awt.* …

java intellij-idea java-11 adoptopenjdk openjdk-11

7
推荐指数
1
解决办法
4066
查看次数

标签 统计

java ×2

adoptopenjdk ×1

buffer ×1

intellij-idea ×1

java-11 ×1

nio ×1

openjdk-11 ×1