2012-08-31 6 views
-3

으로 올바르게 반환합니다. JNI에서 16 바이트 배열을 하드 코딩하고 메서드로 반환하려고합니다. JNI에서 하드 코드 된 바이트 []를 Java

static jbyteArray JNICALL getKeyBytes(JNIEnv *env, jobject thiz) 
{ 
    F_LOG; 
    Mutex::Autolock _m(sLock); 


    jbyteArray result; 
    jbyte* resultType = new jbyte[16]; 
    result = (*env)->NewByteArray(env, 16); //line 214 
    resultType = {52, 14, 25, 32, 75, 83, 35, 89, 40, 69, 35, 73, 84, 82, 35, 30}; 
    (*env)->SetByteArrayRegion(env, result, 0, 16, resultType); 
    delete [] resultType; 

    return result; 
} 

작동하지 않습니다 내가받을 다음과 같은 오류

NativeCodeCaller.cpp:214:17: error: base operand of '->' has non-pointer type '_JNIEnv'

NativeCodeCaller.cpp:215:78: warning: extended initializer lists only available with -std=c++0x or -std=gnu++0x

NativeCodeCaller.cpp:215:78: error: cannot convert "brace-enclosed initializer list>" to 'jbyte*' in assignment

NativeCodeCaller.cpp:216:8: error: base operand of '->' has non-pointer type '_JNIEnv'

어떤 빠른 도움말? :)

+0

계속 하시겠습니까? – Shark

답변

1

오류 base operand of '->' has non-pointer type-> 대신 .을 사용해야 함을 나타냅니다.

따라서 (*env).NewByteArray(env, 16); 또는 env->NewByteArray(env, 16);을 사용합니다.

다음 줄 (215)에 cannot convert "brace-enclosed initializer list>" to 'jbyte*' in assignment이라는 또 다른 오류가 있습니다. 대입의 중괄호 구문은 배열/포인터를 선언 할 때만 유효하기 때문입니다. 컴파일러도 그렇지만 확실하지는 않습니다). 이 도움이

jbyte resultType[16] = {52, 14, 25, 32, 75, 83, 35, 89, 40, 69, 35, 73, 84, 82, 35, 30}; 

희망 :

당신과 시도해야합니다.

+0

가까이 있지만 시가는 없습니다. 어쨌든 내가 바이트를 가로 질러 가져 오는 경우 이것을 받아 들일 것입니다. 그것이 그 것이었던 – Shark

+0

사실, [16]은 결정적이었다. 다시 한 번 감사드립니다 :) 그러나 env->를 사용하면 메서드에서 전달할 필요가 없습니다. – Shark

+0

다행스럽게도 :) – Alex

관련 문제