Skip to main content

JNI Trouble accessing Double Object in C++

2 replies [Last post]
h_p
Offline
Joined: 2010-01-14
Points: 0

I am trying to access a Double Object set in Java in my c++ code. However I am getting segmentation error. My Java native method looks like:

public static native Object print(Data d);

And my JNI method looks like following. Please help.

Thank you.

Regards,
-H

JNIEXPORT jobject JNICALL Java_GenericPeer_print (JNIEnv *jenv, jclass jcls, jobject data) {
ofstream outFile;
jdoubleArray jobj; jint dlen;
outFile.open("/home/usr/Documents/outputGenericFile.txt", ios::app);
jclass peerCls = jenv->GetObjectClass(data);

jmethodID mGetValue = jenv->GetMethodID(peerCls, "getValue","()Ljava/lang/Object;");
if(mGetValue == NULL){
outFile<<"Could not find getValue()"<CallObjectMethod(data, mGetValue);
jdouble *idata = jenv->GetDoubleArrayElements(jobj, NULL); //-----------------------> Getting a segmentation fault here
dlen = jenv->GetArrayLength(jobj);
jint val;
for(int i = 0; iReleaseIntArrayElements(jobj, idata, 0);
return jobj;
}

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
jesdisciple
Offline
Joined: 2008-05-01
Points: 0

Hi h_p,

Sorry I took so long to respond. By now you've probably found help elsewhere.

Anyway, JNI questions should go to http://forums.sun.com/forum.jspa?forumID=52 . However, please do come back to help out here. I don't use Java; I only try to garden a community out of this forum because I'm a FOSS geek.

--
Chris

h_p
Offline
Joined: 2010-01-14
Points: 0

Hello,

The solution of the above problem can be found here:

http://stackoverflow.com/questions/2630529/jni-how-to-access-java-object...

I hope it helps someone.

H