0

CpuPerc() is not public in CpuPerc; cannot be accessed from outside package

...

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

    }
}

What is this error and how can I fix it. I am using SIGAR API.

Arc
  • 441
  • 1
  • 9
  • 26
  • What part of the error message don't you understand? http://docs.oracle.com/javase/tutorial/java/javaOO/accesscontrol.html – SLaks Feb 09 '14 at 14:20
  • @SLaks none of it really, its quite new to me. You seem to know more about this then me, so can you please help me out? – Arc Feb 09 '14 at 14:22

1 Answers1

1

The error message is telling you that instances CpuPerc were not intended to be obtained this way (package-private constructor). getCpuPerc is an instance method of Sigar which returns the required instance.

Sigar sigar = new Sigar();
CpuPerc perc = sigar.getCpuPerc();
System.out.println(perc.getCpuPerc());
Reimeus
  • 158,255
  • 15
  • 216
  • 276