I'm trying to populate an object with data from a C DLL, called via JNI from
Java.
What I have is this:
public class returnValue
{
private String username;
private String cert;
public void setUsername(String username)
{
this.username = username;
}
public String getUsername()
{
return this.username;
}
public void setCert(String cert)
{
this.cert = cert;
}
public String getCert()
{
return this.cert;
}
}
here's the function Declaration in the Java (for the API in the DLL I want
to call):
public native void getBiometric(String username,
String nonce,
String cert,
long sessionId,
long keyId,
short enroll,
short typeQualifier,
short usageQualifier,
short deviceType,
returnValue r);
Here's where I call it from the Java:
r = new returnValue();
r.setCert("C");
r.setUsername("U");
System.out.println("Username being sent is : " + r.getUsername());
System.out.println("Cert being sent is : " + r.getCert());
getBiometric(username, nonce, "ABC", (long)1000, keyId, (short)0,
(short)2, (short)22, (short)1, r);
System.out.println("Username returned is : " + r.getUsername());
System.out.println("Cert returned is : " + r.getCert());
Basically I want to populate the returnValue object in the C.
Anyhow here's the C Code:
JNIEXPORT void JNICALL Java_JavaCapture_getBiometric(JNIEnv *env,
jobject jo,
jstring u, // The username
jstring n, // The nonce
jstring c, // The cert
jlong sid, // The Session ID
jlong kid, // The Key ID
jshort e, // The Enroll data
jshort tq, // The Type Qualifier
jshort uq, // The Usage Qualifier
jshort dt, // The Device Type
jobject retVal) // The return value
{
//do stuff
// Populate the return object
jclass cls = env->GetObjectClass(retVal);
jmethodID setUsername = env->GetMethodID(cls, "setUsername",
"(Ljava/lang/String;)V");
if (setUsername == 0)
return;
env->CallVoidMethod(retVal, setUsername, "Martin");
jmethodID setCert = env->GetMethodID(cls, "setCert",
"(Ljava/lang/String;)V");
if (setUsername == 0)
return;
env->CallVoidMethod(retVal, setCert, "Cert!!");
}
This works fine in the C, but as soon as the DLL returns to java it bombs -
it never gets to the second set of println's
The error is:
Exception in thread "main" java.lang.NullPointerException
at java.lang.StringBuffer.append(StringBuffer.java:398)
at JavaCapture.getBio(JavaCapture.java:54)
at JavaCapture.main(JavaCapture.java:131)
Any help would be great !!
Thanks !!
Martin.
-----------== Posted via Newsfeed.Com - Uncensored Usenet News ==----------
http://www.newsfeed.com The #1 Newsgroup Service in the World!
-----= Over 100,000 Newsgroups - Unlimited Fast Downloads - 19 Servers =-----
Martin Stephenson wrote:
Signature mismatch:
> jmethodID setUsername = env->GetMethodID(cls, "setUsername",
> "(Ljava/lang/String;)V");
> if (setUsername == 0)
> return;
> env->CallVoidMethod(retVal, setUsername, "Martin");
setUserName is prototyped to take a java.lang.String, but you are
passing "Martin" which is NOT a java.lang.String...
Try:
//...
env->CallVoidMethod(retVal, setUserName,
env->NewStringUTF("Martin));
//...
env->CallVoidMethod(retVal, setCert,
env->NewStringUTF("Cert!!"));
HTH.
--
___ _ Blair Wyman IBM Rochester
( /_) / _ ' _ (507)253-2891 bla...@us.ibm.com
__/__)_/_<_/_/_/_' Opinions expressed may not be those of IBM