高手们请问这个“本地方法”怎么用  为什么我那样写不行啊?先谢了!
Native methods 本地方法:本地方法是指使用依赖平台的语言编写的方法,它用来完成Java无法处理的某些依赖于平台的功能。 我的测试类:
import java.io.IOException;
public class Test { /**
 * @param args
 */
public static void main(String[] args) {
// TODO Auto-generated method stub
Process p=null;
String cmdarray[]=new String[]{"ipconfig /all"};
try {
p=execInternal(cmdarray,null,null);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
private native static Process execInternal(String cmdarray[], String envp[], String path) 
 throws IOException;}
弹出  Java Virtual Machine Launcher
    
      Fatal exception occurred.  Program will exit.
 错误:
java.lang.UnsatisfiedLinkError: execInternal
at Test.execInternal(Native Method)
at Test.main(Test.java:15)
Exception in thread "main"

解决方案 »

  1.   

    ..........................
    要写DLL的
    你去下载个 java高级JNI核心理论教程
    那个张孝祥的徒弟讲的
    JNI这块讲的还不错的不错你的用法 好像是想调用ipconfig.exe????
    那这样写
    Runtime.getRuntime().exec("ipconfig /all");
      

  2.   

    JNI是Java调用C/C++等其它语言编写的方法, 在Windows平台一般是dll你这个情况, 是想调用命令行操作
    Process process = Runtime.getRuntime().exec("ipconfig /all"); Scanner sc = new Scanner(new BufferedInputStream(
    process.getInputStream()));
    StringBuilder builder = new StringBuilder(); while (sc.hasNext()) {
    builder.append(sc.nextLine().trim() + "\n");
    } sc.close();这样就可以获得ipconfig /all 的输出, 接着对builder.toString()进行处理
      

  3.   


    private  native  Process  execInternal(String  cmdarray[],  String  envp[],  String  path)  throws  IOException;  这个方法我是从Runtime类里拷出来的,我是想知道为什么放在Runtime 里可以,放在我自己的类里不行?Runtime.getRuntime().exec(  "ipconfig  /all  "); 这个我会用,但不是我的目的,但还是谢谢兄弟的帮忙,呵呵!
      

  4.   

    你找到那个dll就可以了  
    你把jre下面的dll都拷到跟class同一目录 试试
      

  5.   


    http://www.zhanso.com/JAVA/JAVA_1_1808.html
      

  6.   

    dll 我都拷进去,还是不行,不过应该不用拷过去吧?高手们帮帮忙啊,学习中!
    或者看下,下面这个  同样的问题  public static native long currentTimeMillis();这个方法在Date类里拷出来的,为什么放我自己的类里不行???public   class   TestNative   {     
      public static native long currentTimeMillis();
         public static void main(String[] args) {
            System.out.print(new TestNative().currentTimeMillis()); 
         }
      }
      

  7.   

    因为它们还要依靠别的代码来实现,并不是简单的考过来就可以了你如果看了源代码就知道,他们还有一个static{
        registNatives();
    }
      

  8.   

    楼上历害了,可我把这句也加进去了,dll也都拷进去了(放在.class同级)为什么还不行?public class TestNative {
    private static native void registerNatives();
    static {
    registerNatives();
    }
    public static native long currentTimeMillis();
    public static void main(String[] args) {
    TestNative.currentTimeMillis();
    System.out.print("");
    }
    }java.lang.UnsatisfiedLinkError: registerNatives
    at TestNative.registerNatives(Native Method)
    at TestNative.<clinit>(TestNative.java:4)
    Exception in thread "main"