1. The exception you are getting has nothing to do with strings or char arrays being
passed. What is really happening is the java runtime cannot find the native code module you just compiled
BTW you did'n t say what OS you are using. UNIX, LINUX or NT. In any case the Library path
has not been specified for this native module.

2.) The JavaDocs for nativie code manipulation of passed jstring objects has the following methods:
"String Operations
 

NewString

jstring NewString(JNIEnv *env, const jchar *unicodeChars,
jsize len);

Constructs a new java.lang.String object from an array of Unicode characters.

PARAMETERS:

env: the JNI interface pointer.

unicodeChars: pointer to a Unicode string.

len: length of the Unicode string.

RETURNS:

Returns a Java string object, or NULL if the string cannot be constructed.

THROWS:

OutOfMemoryError: if the system runs out of memory.
 

GetStringLength

jsize GetStringLength(JNIEnv *env, jstring string);

Returns the length (the count of Unicode characters) of a Java string.

PARAMETERS:

env: the JNI interface pointer.

string: a Java string object.

RETURNS:

Returns the length of the Java string.
 

GetStringChars

const jchar * GetStringChars(JNIEnv *env, jstring string,
jboolean *isCopy);

Returns a pointer to the array of Unicode characters of the string. This pointer is valid until ReleaseStringchars() is called.

If isCopy is not NULL, then *isCopy is set to JNI_TRUE if a copy is made; or it is set to JNI_FALSE if no copy is made.

PARAMETERS:

env: the JNI interface pointer.

string: a Java string object.

isCopy: a pointer to a boolean.

RETURNS:

Returns a pointer to a Unicode string, or NULL if the operation fails.
 

ReleaseStringChars

void ReleaseStringChars(JNIEnv *env, jstring string,
const jchar *chars);

Informs the VM that the native code no longer needs access to chars. The chars argument is a pointer obtained from
string using GetStringChars().

PARAMETERS:

env: the JNI interface pointer.

string: a Java string object.

chars: a pointer to a Unicode string.
 

NewStringUTF

jstring NewStringUTF(JNIEnv *env, const char *bytes);

Constructs a new java.lang.String object from an array of UTF-8 characters.

PARAMETERS:

env: the JNI interface pointer, or NULL if the string cannot be constructed.

bytes: the pointer to a UTF-8 string.

RETURNS:

Returns a Java string object, or NULL if the string cannot be constructed.

THROWS:

OutOfMemoryError: if the system runs out of memory.
 

GetStringUTFLength

jsize GetStringUTFLength(JNIEnv *env, jstring string);

Returns the UTF-8 length in bytes of a string.

PARAMETERS:

env: the JNI interface pointer.

string: a Java string object.

RETURNS:

Returns the UTF-8 length of the string.
 

GetStringUTFChars

const char* GetStringUTFChars(JNIEnv *env, jstring string,
jboolean *isCopy);

Returns a pointer to an array of UTF-8 characters of the string. This array is valid until it is released by
ReleaseStringUTFChars().

If isCopy is not NULL, then *isCopy is set to JNI_TRUE if a copy is made; or it is set to JNI_FALSE if no copy is made.

PARAMETERS:

env: the JNI interface pointer.

string: a Java string object.

isCopy: a pointer to a boolean.

RETURNS:

Returns a pointer to a UTF-8 string, or NULL if the operation fails.
 

ReleaseStringUTFChars

void ReleaseStringUTFChars(JNIEnv *env, jstring string,
const char *utf);

Informs the VM that the native code no longer needs access to utf. The utf argument is a pointer derived from string using
GetStringUTFChars().

PARAMETERS:

env: the JNI interface pointer.

string: a Java string object.

utf: a pointer to a UTF-8 string.
"

Cheers
Chris
 
 

Boris wrote:

Hello everyone!
I have a problem in passing  string between java and c.
I will use native method writted in c ,and pass some string to c for processing.
The class to load liabrary is following:

public class loadIO
{

    public native boolean write(char[] path, char[] name,char[] value);

    static{
    System.loadLibrary("IO");
           }
}

I compile this class successfully and use javah to make a  .h file for c.
In the .c file ,the method declaration is follwing:

JNIEXPORT jboolean JNICALL Java_IO_write
  (JNIEnv *env, jobject obj, jcharArray  path, jcharArray name, jcharArray value)
{
        jchar * buf;

        env->GetCharArrayRegion(path, 0, 100, buf);
...........
}

The liabrary is compiled sucsuccessfully,but when I run java program ,the following
error message is printed:
java.lang.UnsatisfiedLinkError: write
    at com.JiaTeng.adsl.adslCfgGui.ConfigDlg.<init>(ConfigDlg.java:124)
    at com.JiaTeng.adsl.adslCfgGui.ConfigDlg.<init>(ConfigDlg.java:130)
    at com.JiaTeng.adsl.adslCfgGui.ConfigDlg.main(ConfigDlg.java:161)
    at symantec.tools.debug.MainThread.run(Agent.java:48)

Distinctly,the error occured in passing string between java and c.
But I don't know what is wrong in it,because native is difficult to debug.
Who anyone can tell me where the bug is ?
If I use String instead of char[],the corresponding type in c is jarray.
How can I process jarray type in c?

Thank you very much!

Boris

----------------------------------------------------------------------
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]

begin:vcard 
n:Hinds;Christopher
tel;fax:212-271-3008
tel;work:212-271-3000
x-mozilla-html:FALSE
url:www.2bridge.com
org:2Bridge Software , E-Commerce Portals;Software Development 
version:2.1
email;internet:[EMAIL PROTECTED]
title:Senior Software Engineer , Project Manager
adr;quoted-printable:;;33 Whitehall St=0D=0A22nd Fl.;New York;NY;10003;USA
fn:Christopher Hinds
end:vcard

Reply via email to