KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I need help with my android project. I want to pass a buffer from java to jni, and my C++ code will populate the data. Then java will display them on the screen. I am not familiar much with C++ and have no idea how to write to write to the buffer. this is what i got. in java ByteBuffer bb = ByteBuffer.allocateDirect(216); IssmJni.processBuffer(bb); native method public static native void processBuffer(ByteBuffer bb); I don't use jni_onload, so no javah in C++ static void fillBuffer(JNIEnv *env, jclass clazz, jobject buf) { double *dBuf = env->GetDirectBufferAddress(env, buf); } I am stuck here, can I do double dbuf? or is it has to be a char ? Let said I want to write 1,2,3,4,5 to this dbuf, how do I do it? i am thinking of dbuf.put(1); ... dbuf.put(5) but it is not working. and after populating it, do I just call bb.get(position) in java? Someone clarify this for me please, example would be appreciated Thank you this is my table of native methods static JNINativeMethod method_table[] = { {"fac" , "(J)J" , (void *) factorial}, {"getBuffer", "()[D" , (void *) getBufferNative}, //{"processBuffer", "(Ljava/nio/ByteBuffer)V", (void *) fillBuffer}}; The other two works fine except the last one.
Tags (comma-separated)
Save Edits
Cancel