需要学习的东西太多。想起了只有这么少的时间,要学习这么多东西。
不会。不过提示说是'main'抛出异常。
at HelloWorld.main(HelloWorld.java:16)
new HelloWorld().displayHelloWorld("szx");

解决方案 »

  1.   

    你的例子没有问题,实现也没有问题(俺在LINUX平台上已经为你测试通过了)。
    看看你的异常UnsatisfiedLinkError,说明你没有在PATH中找到名为“displayHelloWorld”的动态链接库。给出你的例子在Linux下验证的过程:
    1. javac HelloWorld.java
    2. javah HelloWorld
    3. edit HelloWorld.c
    4. gcc -c -I/usr/java/j2sdk1.4.2_02/include -I/usr/java/j2sdk1.4.2_02/include/linux HelloWorld.c
    5. gcc -shared -o libHelloJni.so HelloWorld.o
    6. export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:.
    7. java HelloWorld
    8. 输出结果:“Hello,szx”
      

  2.   

    如果有问题,可以看看这个简单的教程:
    <<
    http://java.sun.com/docs/books/tutorial/native1.1/stepbystep/index.html
    >>
      

  3.   

    以下是我的一个例子程序,看看对你有没有帮助
    // Console.java
    package jnidemo;/**
     * <p>Title: </p>
     * <p>Description: </p>
     * <p>Copyright: Copyright (c) 2003</p>
     * <p>Company: </p>
     * @author not attributable
     * @version 1.0
     */public class Console
    {
        public Console()
        {
        }    public static void main(String[] args)
        {
            CppExtention cpp=new CppExtention();
            String context[]={"English","汉字","English汉字"};
            cpp.print("This is a test string.");
            cpp.printArray(context);
        }
    }// CppExtention.java
    package jnidemo;/**
     * <p>Title: </p>
     * <p>Description: </p>
     * <p>Copyright: Copyright (c) 2003</p>
     * <p>Company: </p>
     * @author not attributable
     * @version 1.0
     */public class CppExtention
    {
        static
        {
            System.loadLibrary("CppExtention");
        }    public native void cppPrint(String s);    public native void cppPrintArray(String[] contxt,int count);    public CppExtention()
        {
        }    public boolean print(String s)
        {
            try
            {
                cppPrint(s);
            }
            catch(Exception e)
            {
                return false;
            }
            return true;
        }    public boolean printArray(String[] context)
        {
            try
            {
                cppPrintArray(context,context.length);
            }
            catch(Exception e)
            {
                return false;
            }
            return true;    }
    }
      

  4.   

    // CppExtention.cpp// CppExtention.cpp : Defines the initialization routines for the DLL.
    //
    /////////////////////////////////////////////////////////////////////////////
    #include "stdafx.h"
    #include "CppExtention.h"
    #include "jnidemo_CppExtention.h"#ifdef _DEBUG
    #define new DEBUG_NEW
    #undef THIS_FILE
    static char THIS_FILE[] = __FILE__;
    #endif
    /////////////////////////////////////////////////////////////////////////////
    // CCppExtentionApp
    /////////////////////////////////////////////////////////////////////////////
    BEGIN_MESSAGE_MAP(CCppExtentionApp, CWinApp)
    //{{AFX_MSG_MAP(CCppExtentionApp)
    // NOTE - the ClassWizard will add and remove mapping macros here.
    //    DO NOT EDIT what you see in these blocks of generated code!
    //}}AFX_MSG_MAP
    END_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////
    // CCppExtentionApp construction
    /////////////////////////////////////////////////////////////////////////////
    CCppExtentionApp::CCppExtentionApp()
    {
    // TODO: add construction code here,
    // Place all significant initialization in InitInstance
    }/////////////////////////////////////////////////////////////////////////////
    // The one and only CCppExtentionApp object
    /////////////////////////////////////////////////////////////////////////////
    CCppExtentionApp theApp;/////////////////////////////////////////////////////////////////////////////
    // cppPrint
    /////////////////////////////////////////////////////////////////////////////
    JNIEXPORT void JNICALL Java_jnidemo_CppExtention_cppPrint(JNIEnv *env, jobject obj, jstring jstr)
    {
    wchar_t* cstr=(wchar_t*)(*env).GetStringChars(jstr,NULL);
    int size=(*env).GetStringLength(jstr);
    CString wstr=CString(cstr,size);
    AfxMessageBox(wstr);
    }/////////////////////////////////////////////////////////////////////////////
    // cppPrintArray
    /////////////////////////////////////////////////////////////////////////////
    JNIEXPORT void JNICALL Java_jnidemo_CppExtention_cppPrintArray(JNIEnv *env, jobject obj, jobjectArray context, jint count)
    {

    for(int i=0;i<count;i++)
    {
    jstring jstr=(jstring)(*env).GetObjectArrayElement(context,i);
    wchar_t* cstr=(wchar_t*)(*env).GetStringChars(jstr,NULL);
    int size=(*env).GetStringLength(jstr);
    CString wstr=CString(cstr,size);
    AfxMessageBox(wstr);
    }
    }// jnidemo_CppExtention.h
    /* DO NOT EDIT THIS FILE - it is machine generated */
    #include <jni.h>
    /* Header for class jnidemo_CppExtention */#ifndef _Included_jnidemo_CppExtention
    #define _Included_jnidemo_CppExtention
    #ifdef __cplusplus
    extern "C" {
    #endif
    /*
     * Class:     jnidemo_CppExtention
     * Method:    cppPrint
     * Signature: (Ljava/lang/String;)V
     */
    JNIEXPORT void JNICALL Java_jnidemo_CppExtention_cppPrint
      (JNIEnv *, jobject, jstring);/*
     * Class:     jnidemo_CppExtention
     * Method:    cppPrintArray
     * Signature: ([Ljava/lang/String;I)V
     */
    JNIEXPORT void JNICALL Java_jnidemo_CppExtention_cppPrintArray
      (JNIEnv *, jobject, jobjectArray, jint);#ifdef __cplusplus
    }
    #endif
    #endif
      

  5.   


    把生成的dll文件放到c:\winnt\system32下
      

  6.   

    《JAVA编程思想》里无说吗?
    好像有JAVA原生接口吧,你可看看
      

  7.   

    成功了,谢谢大家的帮忙,是我的dll, path没有放好。
    谢谢大家!谢谢大家!
    我已经另开一贴http://expert.csdn.net/Expert/topic/2574/2574810.xml?temp=.6328852,回答过的人来接分啊!!
    呵呵!!
    给足两百分