Skip to main content

JNI Trouble accessing Double Object in C++

2 replies [Last post]
Joined: 2010-01-14

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.


JNIEXPORT jobject JNICALL Java_GenericPeer_print (JNIEnv *jenv, jclass jcls, jobject data) {
ofstream outFile;
jdoubleArray jobj; jint dlen;"/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.
Joined: 2008-05-01

Hi h_p,

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

Anyway, JNI questions should go to . 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.


Joined: 2010-01-14


The solution of the above problem can be found here:

I hope it helps someone.