需要学习的东西太多。想起了只有这么少的时间,要学习这么多东西。
不会。不过提示说是'main'抛出异常。
at HelloWorld.main(HelloWorld.java:16)
new HelloWorld().displayHelloWorld("szx");
不会。不过提示说是'main'抛出异常。
at HelloWorld.main(HelloWorld.java:16)
new HelloWorld().displayHelloWorld("szx");
解决方案 »
- java 移位运算符 困惑
- spring+hibernate整合报错
- 搞JOGL的朋友进来看看
- 下午三点班面试 希望高手帮助一下。着急。
- repaint()方法不自动调用update()方法(急 在线等)
- 在线急等!字符的ASC码求解!
- 有没有办法让我的java程序在DOS下运行,有没有那样的虚拟机?
- 那里有用Jbuilder连接在win2000下的SQLserver2000的驱动程序包下载??
- import 语句该如何用?
- 在html中的Applet,图象怎么得不到(access denied)?代码如下:
- 关于Java打包分发方面的问题。
- 大虾你们好,现在我想在JTable加上一列“序号”。请帮忙!
看看你的异常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”
<<
http://java.sun.com/docs/books/tutorial/native1.1/stepbystep/index.html
>>
// 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; }
}
//
/////////////////////////////////////////////////////////////////////////////
#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
把生成的dll文件放到c:\winnt\system32下
好像有JAVA原生接口吧,你可看看
谢谢大家!谢谢大家!
我已经另开一贴http://expert.csdn.net/Expert/topic/2574/2574810.xml?temp=.6328852,回答过的人来接分啊!!
呵呵!!
给足两百分