JNI problem with GetStringUTFLength

N

Neena

I have a method like this...
But my VM throws exception when i make


nameLen = (*env)->GetStringUTFLength(env, serviceName);

what may be wrong???



JNIEXPORT jlong JNICALL
Java_openConnection
(JNIEnv *env, jobject obj, jstring remoteAddress, jstring serviceName,
jint serverChannel)
{


printf("Getting the length...");
nameLen = (*env)->GetStringUTFLength(env, serviceName);
printf("Getting string...");
nameStore = (*env)->GetStringUTFChars(env, serviceName, NULL);
....................
}
 
A

Andrew Thompson

...But my VM throws exception ...
what may be wrong???

I am not experienced enough in JNI to help you, but
it seems that you have not included the exact Exception
that the code causes.

If you can copy/paste at least the first few lines of that,
it might help others see what is going wrong.

HTH
 
G

Gordon Beaton

I have a method like this...
But my VM throws exception when i make

nameLen = (*env)->GetStringUTFLength(env, serviceName);

what may be wrong???

What exception *exactly*? What does ExceptionDescribe() say?

How did you detect the exception, and how do you know it occurs in
exactly that location?

After the code raises the exception, it is an error to continue
without handling it or returning from the native method. You do
neither of these things in the code you've posted.

Also, realize that printf() to stdout may not appear immediately, thus
obscuring the exact location of the error. Use fprintf(stderr)
instead.

/gordon
 
N

Neena

The error shown is:


Calling Native Method openConnection
Getting the length...
Unexpected Signal : EXCEPTION_ACCESS_VIOLATION (0xc0000005) occurred at
PC=0x807
8CCC
Function=[Unknown.]
Library=C:\Program Files\Java\j2re1.4.2_03\bin\client\jvm.dll

NOTE: We are unable to locate the function name symbol for the error
just occurred. Please refer to release documentation for possible
reason and solutions.


Current Java thread:
 
G

Gordon Beaton

Calling Native Method openConnection
Getting the length...
Unexpected Signal : EXCEPTION_ACCESS_VIOLATION (0xc0000005) occurred at

This is not an exception in the Java sense. This indicates that you've
got an error in your code, that it attempted to access memory at a
location you weren't permitted to access (apparently at location
0xc0000005).

The error is not necessarily in openConnection(), even though your
program was in that method when it crashed. The actual error could
have occurred earlier in a previous native call.

/gordon
 
C

Chris Uppal

Gordon said:
Also, realize that printf() to stdout may not appear immediately, thus
obscuring the exact location of the error.

Especially when:
printf("Getting the length...");

the printf() lacks a carriage return.

-- chris
 
R

Roedy Green

Without a C or MASM style debugger that will be hard to track. The
best you can do is pepper your code with "I am here" statements, and
constantly call some sanity check method that checks that all values
are reasonable. That will help you nail down just where it dies.
However, in C the source of the problem can be miles away in the code.

The traditional c style errors are likely getting you:
1. failure to initialise
2. subscript out of range.
3. dereferencing a null pointer.

Perhaps just a thorough desk check to thing through those, and pepper
your C code with asserts to ensure you assumptions are valid.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,981
Messages
2,570,188
Members
46,731
Latest member
MarcyGipso

Latest Threads

Top