Прототип для SetByteArrayRegion()
:
void SetByteArrayRegion(JNIEnv *env, jbyteArray array, jsize start, jsize len, jbyte *buf);
Последний аргумент - буфер памяти, из которого SetByteArrayRegion()
будет скопирован в массив Java.
Вы никогда не инициализируете этот буфер. Вы делаете:
jbyte* resultType;
*resultType = 7;
Я удивлен, что вы не получаете дамп ядра, поскольку вы записываете 7
в какое-то случайное место в памяти. Вместо этого сделайте это:
jbyte theValue;
theValue = 7;
(*env)->SetByteArrayRegion(env, result, 0, 1, &theValue);
В целом,
// Have the buffer on the stack, will go away
// automatically when the enclosing scope ends
jbyte resultBuffer[THE_SIZE];
fillTheBuffer(resultBuffer);
(*env)->SetByteArrayRegion(env, result, 0, THE_SIZE, resultBuffer);
или
// Have the buffer on the stack, need to
// make sure to deallocate it when you're
// done with it.
jbyte* resultBuffer = new jbyte[THE_SIZE];
fillTheBuffer(resultBuffer);
(*env)->SetByteArrayRegion(env, result, 0, THE_SIZE, resultBuffer);
delete [] resultBuffer;