0

我已经从他们的网站下载了 Sigar API,并将sigar.jar文件包含在我的 Eclipse 项目中。

但问题是我需要.java文件才能将我的项目转换为 obj-c。

因此,我从 github 下载了 zip 文件并从中复制了 src 文件夹,sigar-master/bindings/java/src/org/hyperic/sigar但在其中找不到某些类。

给定的示例代码在包含 jar 时运行良好,但当包含 .java 文件时,代码未运行。

我哪里错了?

谢谢!


代码:

import java.io.*;
import java.util.*;
import java.text.*;
import java.lang.*;


import org.hyperic.sigar.Mem; // Eclipse says that The import org.hyperic.sigar.Mem cannot be resolved
import org.hyperic.sigar.Sigar;
import org.hyperic.sigar.SigarException;

public class MemExample {

private static Sigar sigar = new Sigar();

public static void getInformationsAboutMemory() {
    System.out.println("**************************************");
    System.out.println("*** Informations about the Memory: ***");
    System.out.println("**************************************\n");

    Mem mem = null;  // Mem cannot be resolved to a type
    try {
        mem = sigar.getMem();  // The method getMem() from the type Sigar refers to the missing type Mem
    } catch (SigarException se) {
        se.printStackTrace();
    }

    System.out.println("Actual total free system memory: "
            + mem.getActualFree() / 1024 / 1024+ " MB");
    System.out.println("Actual total used system memory: "
            + mem.getActualUsed() / 1024 / 1024 + " MB");
    System.out.println("Total free system memory ......: " + mem.getFree()
            / 1024 / 1024+ " MB");
    System.out.println("System Random Access Memory....: " + mem.getRam()
            + " MB");
    System.out.println("Total system memory............: " + mem.getTotal()
            / 1024 / 1024+ " MB");
    System.out.println("Total used system memory.......: " + mem.getUsed()
            / 1024 / 1024+ " MB");

    System.out.println("\n**************************************\n");


}

public static void main(String[] args) throws Exception{ // line 45

            getInformationsAboutMemory();

            }

}

安慰:

Exception in thread "main" java.lang.Error: Unresolved compilation problem: 

at MemExample.main(MemExample.java:45)

它说Mem cannot be resolved to a type

当我解压缩时sigar.jar,里面有一个类Mem.class

4

0 回答 0