【问题标题】:Java cannot be accessed error from outside package error无法从外部包错误访问 Java 错误
【发布时间】:2014-02-10 00:58:24
【问题描述】:

CpuPerc() 在 CpuPerc 中不公开;无法从外部包访问

...

import org.hyperic.sigar.*;
import org.hyperic.sigar.Cpu;
import org.hyperic.sigar.CpuPerc;

/**
 *
 * @author John
 */

public class GetCpu {
    public void Start() {
            Sigar sigar = new Sigar();
            CpuPerc perc = new CpuPerc();
            System.out.println(getCpuPerc()); // error appears here

    }
}

这是什么错误,我该如何解决。我正在使用 SIGAR API。

【问题讨论】:

标签: java sigar


【解决方案1】:

错误消息告诉您实例 CpuPerc 不打算以这种方式获得 (package-private constructor)。 getCpuPercSigar 的一个实例方法,它返回所需的实例。

Sigar sigar = new Sigar();
CpuPerc perc = sigar.getCpuPerc();
System.out.println(perc.getCpuPerc());

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-11-09
    • 2018-06-27
    • 1970-01-01
    • 1970-01-01
    • 2018-03-09
    • 1970-01-01
    • 1970-01-01
    • 2016-06-17
    相关资源
    最近更新 更多