我使用google nexus s的nfc功能来开发我的基于RF卡的程序。这是我的方法,我认为问题出在数据对象上
unsigned char *CNFCFunList::jbyteArray2Byte(jbyteArray data, int *outLen)
{
LOGI("jbyteArray2Byte begin");
if (data == NULL)
{
LOGI("data is NULL");
return 0;
}
jsize size = m_pJNIEnv->GetArrayLength(data);
LOGI("GetArrayLength begin %d",size);
//LOGI("GetByteArrayElements begin,data length = %d",env->GetArrayLength(data));
jbyte * olddata = (jbyte*)m_pJNIEnv->GetByteArrayElements(data, 0);
jsize oldsize = m_pJNIEnv->GetArrayLength(data);
unsigned char* bytearr = (unsigned char*)olddata;
*outLen = (int)oldsize;
return bytearr;
}
但我得到 JNI WARNING: JNI method called with exception pending in Lcom/uai/jni/...;(J[BJI) (GetArrayLength) Pending exception is:
我也得到了例外
I/dalvikvm(5836): java.io.IOException: Transceive failed
11-23 10:19:35.269: I/dalvikvm(5836): at android.nfc.TransceiveResult.getResponseOrThrow(TransceiveResult.java:52)
11-23 10:19:35.269: I/dalvikvm(5836): at android.nfc.tech.BasicTagTechnology.transceive(BasicTagTechnology.java:151)
11-23 10:19:35.269: I/dalvikvm(5836): at android.nfc.tech.IsoDep.transceive(IsoDep.java:172)
11-23 10:19:35.269: I/dalvikvm(5836): at com.uai.jni.libUai.uaiGenKeyPair(Native Method)
11-23 10:19:35.269: I/dalvikvm(5836): at